如何在运行时从UITableView中删除单元格?

时间:2012-07-02 15:42:15

标签: iphone uitableview

我想从UITableView中删除特定的单元格

我找到了deleteRowsAtIndexPaths:withRowAnimation:

我尝试将cell.frame更改为0,0,0,0

我尝试.hidden = YES

对我来说没什么用。

有什么想法吗?

谢谢!

2 个答案:

答案 0 :(得分:1)

尝试添加开始和结束调用以进行编辑:

[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:deletePaths withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];

或者,如果您正在使用基础数据源,请从数据源中删除该对象并调用[tableView reloadData];

答案 1 :(得分:0)

使用此方法从表格视图中删除单元格,并手动从阵列中删除相同的对象,通过这些对象在tableview上显示数据。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

   if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source

        [yourArray removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];

       } 
       [tableView reloadData];
}

希望这会对你有帮助..

相关问题