UITableviewcell的删除操作

简介: //编辑类型-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ return UITableViewCellEditingStyleDelete;}//允许编辑-(BOOL
//编辑类型
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete;
}
//允许编辑
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return  YES;
}
//具体操作
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

   if(editingStyle==UITableViewCellEditingStyleDelete){
        //数据更新操作
        [self.tbview deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
    }



}

上面是cell删除操作,但是光这样还不行,在执行删除操作后会reload tableview,此时不光要保证数据更新,还要保证section和row的number更新。

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return ????;//判断

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return ????;//判断
}
相关文章
|
3月前
|
开发者 iOS开发
介绍 UITableView 和 UICollectionView,它们的区别是什么?
介绍 UITableView 和 UICollectionView,它们的区别是什么?
54 0
UITableView的创建
UITableView的创建
75 0
|
iOS开发
iOS UITableViewCell嵌套CollectionView,tableview和collectionview同时滑动bug修复
iOS UITableViewCell嵌套CollectionView,tableview和collectionview同时滑动bug修复
909 0
UIcollectionViewCell(UItableviewcell)长按删除操作
功能简单,陷阱不少: 主要涉及两个功能: 1、长按手势:UILongPressGestureRecognizer 2、cell自带的删除操作:deleteItemsAtIndexPaths 首先为cell添加长按手势: UILongPressGestureRecognizer* longgs=[[UILongPressGestureRecognizer all
1458 0