2010-10-21 87 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