麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

iOS開(kāi)發(fā)日記1-tableview編輯

2019-11-14 18:31:55
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

今天博主有一個(gè)tableview編輯的需求,遇到了一些困難點(diǎn),在此和大家分享,能夠共同進(jìn)步.

tableview的編輯是通過(guò)[self.tableview setEditing: BOOL1 animotion: BOOL2];進(jìn)入的,如果需要進(jìn)入編輯模式,則調(diào)用方法,將BOOL1改為YES.如果要退出編輯模式,則調(diào)用方法,將BOOL1改為NO.BOOL2為是否使用動(dòng)畫(huà).

如果你想將編輯這個(gè)button由文字改為圖片,想通過(guò)setBackGroudImage這個(gè)方法替換文字,你會(huì)發(fā)現(xiàn)圖片會(huì)因?yàn)闊o(wú)法設(shè)置frame而產(chǎn)生拉伸,效果不理想.解決方法:你可以自定義rightBarButtonItem,重寫(xiě)代理方法.下面將tableview的編輯的代碼貼出來(lái),與大家分享

- (void)viewDidLoad {

    [super viewDidLoad];

 

    //編輯按鈕

    self.navigationItem.rightBarButtonItem = self.editButtonItem;

    self.navigationItem.rightBarButtonItem.title = @"編輯";

    self.navigationItem.rightBarButtonItem.tintColor=[UIColor blackColor];

}

#PRagma mark---------tableView的編輯(刪除,插入)

//點(diǎn)擊編輯按鈕

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {

    [super setEditing:editing animated:animated];

    // Don't show the Back button while editing.

//    [self.navigationItem setHidesBackButton:editing animated:YES];

    if (editing) {

        self.navigationItem.rightBarButtonItem.title = @"完成";

        NSLog(@"abc");

    }else {//點(diǎn)擊完成按鈕

        self.navigationItem.rightBarButtonItem.title = @"編輯";

        NSLog(@"123");

    }

    [_customView.tableView setEditing:editing animated:YES];

}

//2.設(shè)置定制分區(qū)(section)中的行(row)是否可以被編輯

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

//    if (indexPath.section==0) {

//        return NO;

//    }

    return YES;

}

//3.設(shè)置指定的分區(qū)(section)的行(row)編輯的樣式(添加,刪除)

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (indexPath.section==1) {

        return UITableViewCellEditingStyleInsert;

    }

    return UITableViewCellEditingStyleDelete;

}

//4.編輯完成(先操作數(shù)據(jù)源,再修改UI)

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (editingStyle==UITableViewCellEditingStyleDelete) {

        NSLog(@"刪除");

        //同步更新beginUpdates 和 endUpdates 之間修改的UI和數(shù)據(jù)

        [_customView.tableView beginUpdates];

        

        //1.刪除數(shù)據(jù)

        NSString *key=_allDataDic.allKeys[indexPath.section];

        NSMutableArray *array=_allDataDic[key];

        [array removeObjectAtIndex:indexPath.row];

        //2.刪除UI

        //刪除行

        [_customView.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];

        if (array.count==0) {

            

            //刪除區(qū)頭上的數(shù)據(jù)(刪除key對(duì)應(yīng)的小數(shù)組)

            NSString *key=_allDataDic.allKeys[indexPath.section];

            [_allDataDic removeObjectForKey:key];

 

            //當(dāng)某個(gè)分區(qū)中只剩一個(gè)cell的時(shí)候(或者小數(shù)組中只剩一個(gè)數(shù)據(jù)的時(shí)候),刪除時(shí),也要把區(qū)頭刪除掉

            NSIndexSet *indexSet=[NSIndexSet indexSetWithIndex:indexPath.section];

            [_customView.tableView deleteSections:indexSet withRowAnimation:UITableViewRowAnimationLeft];

        }

        

        [_customView.tableView endUpdates];

        

    }else if (editingStyle==UITableViewCellEditingStyleInsert)

    {

        NSLog(@"插入");

        //1.插入數(shù)據(jù)

        NSString *key=_allDataDic.allKeys[indexPath.section];

        NSMutableArray *array=_allDataDic[key];

        [array insertObject:@"昌平" atIndex:indexPath.row];

        //2.插入U(xiǎn)I(cell)        

      //  NSIndexPath *indexPath1=[NSIndexPath indexPathForRow:0 inSection:indexPath.section];//保證每次插入數(shù)據(jù)都在第一行

        [_customView.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];        

    }

}

 

http://www.jianshu.com/p/7c3d72fd9616?plg_nld=1&plg_uin=1&plg_auth=1&plg_nld=1&plg_usr=1&plg_vkey=1&plg_dev=1


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: av中文在线观看 | 欧美成人精品一区二区 | 污污网站入口 | 久久久国产精品免费观看 | 羞羞的视频免费在线观看 | 久久蜜桃香蕉精品一区二区三区 | 国产影视 | 欧美日韩影视 | 91麻豆精品国产91久久久更新资源速度超快 | 日韩精品久久久久久久电影99爱 | 国产资源在线观看视频 | www.guochan| 色诱亚洲精品久久久久久 | 久久久久久久免费看 | 一级国产航空美女毛片内谢 | 亚洲操比视频 | 毛片在线视频观看 | 日本黄色免费片 | 国产在线精品91 | 538在线精品 | 日本a∨精品中文字幕在线 被啪羞羞视频在线观看 | 日韩av在线网址 | 精品国产视频一区二区三区 | 亚洲综合网站 | 国产成人精品一区二区视频免费 | 久久华人| 看中国一级毛片 | 久久综合给合久久狠狠狠97色69 | 露脸各种姿势啪啪的清纯美女 | 草操视频| 国产免费成人 | 国产精品一区二区三区在线播放 | 91小视频在线观看免费版高清 | 九一免费版在线观看 | 日本特级a一片免费观看 | 在线男人天堂 | 色吧综合网 | 精品中文字幕久久久久四十五十骆 | 91重口视频 | 久久久久国产一区二区三区不卡 | 欧美日本国产精品 |