iOS UITableViewCell的删除

2017-09-20  本文已影响0人  想想8606

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
上一篇 下一篇

猜你喜欢

热点阅读