-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle != UITableViewCellEditingStyleDelete) return;//非编辑删除模式
//先修改模型中的数据
[persons removeObjectAtIndex:indexPath.row];
//刷新表格
//下面的方法必须是模型里的行数和tableView中的行数必须一致
// [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
}
- (IBAction)remove:(UIBarButtonItem *)sender {
//进入编辑模式
BOOL result = !self.tableView.isEditing;
[self.tableView setEditing:result animated:YES];
}
Swift 删除 UITableView 数据
本文介绍了一个在 iOS 开发中如何使用 Swift 实现从 UITableView 中删除指定数据的方法。具体包括判断删除模式、更新数据源并刷新 UITableView 的过程。
2195

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



