//编辑类型
-(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 ????;//判断
}
本文详细介绍了如何在iOS中实现表格视图单元格删除操作,并确保在执行删除操作后,不仅数据得到更新,同时保持section和row编号的正确性。包括编辑模式设置、允许编辑条件判断、单元格删除操作的具体实现以及数据更新后的重新计算section和row数量。
1365

被折叠的 条评论
为什么被折叠?



