2010-10-21 99 views
8

如何删除刷卡上的UITableView行?我知道这个问题已经被问到,但我得到的只是错误。这里的代码:刷卡删除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];  
    } 
} 

但没有任何反应。如果您编写代码,我将不胜感激。

回答

7

删除该行后重新加载表。

[tableView reloadData]; 
+0

OMG!那很简单!非常感谢! – KillaIce 2010-10-21 13:37:50

+1

:)为什么你不接受答案呢? – 2010-10-21 13:40:18

+0

我可以在3分钟内完成:( – KillaIce 2010-10-21 13:41:37

44

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

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

这是更好:) – 2010-10-21 13:44:47

+0

上面的行给了我一个错误,所以这(几乎相同)很好地工作。 '[myTable deleteRowsAtIndexPaths:@ [indexPath] withRowAnimation:UITableViewRowAnimationFade];' – alexdd55 2013-09-07 10:18:05