美文网首页
iOS UITableViewCell的删除

iOS UITableViewCell的删除

作者: 想想8606 | 来源:发表于2017-09-20 09:59 被阅读0次

UITableViewCell的删除,只需要实现以下4个方法:

pragma mark - 左滑删除

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete;
}

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
return @"删除";
}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if(editingStyle == UITableViewCellEditingStyleDelete){
[_timeArray removeObjectAtIndex:indexPath.section];
NSIndexSet *sectionIndex = [NSIndexSet indexSetWithIndex:indexPath.section];
[tableView deleteSections:sectionIndex withRowAnimation:UITableViewRowAnimationAutomatic];
}
}

image.png image.png 左滑删除.png

相关文章

网友评论

      本文标题:iOS UITableViewCell的删除

      本文链接:https://www.haomeiwen.com/subject/qpbssxtx.html