【问题标题】:Swipe to delete UITableView滑动删除 UITableView
【发布时间】:2010-10-21 13:29:41
【问题描述】:

如何在滑动时删除 UITableView 行?我知道问题已被提出,但我只得到错误。代码如下:

-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
    forRowAtIndexPath:(NSIndexPath *)indexPath {
    // If row is deleted, remove it from the list.
    if (editingStyle == UITableViewCellEditingStyleDelete) {
         NSInteger row = [indexPath row];
         [tableDataSource removeObjectAtIndex:row];      
    }
}

但是什么也没发生。如果您编写代码,我将不胜感激。

【问题讨论】:

    标签: iphone uitableview ios


    【解决方案1】:

    最好只删除选中的行,而不是重新加载所有表:

     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    

    【讨论】:

    • 上面的行给了我一个错误,所以这个(几乎相同)工作得很好。 [myTable deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    【解决方案2】:

    删除行后重新加载表。

    [tableView reloadData];
    

    【讨论】:

    • 天哪!就这么简单!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 2012-11-27
    • 2012-07-07
    • 2017-05-20
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多