简体   繁体   English

滑动即可删除UITableView

[英]Swipe to delete UITableView

How can I delete a UITableView row on swipe? 如何在滑动时删除UITableView行? I know the question has been asked, but I get only errors. 我知道问题已被提出,但我只得到错误。 Here's the code: 这是代码:

-(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];      
    }
}

But nothing happens. 但没有任何反应。 I would appreciate if you write code. 如果你编写代码,我将不胜感激。

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

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

删除行后重新加载表。

[tableView reloadData];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM