我有一個tableviewController
。在UINavigationBar
我將添加一個名爲Edit的按鈕。當用戶點擊它時,我需要所有單元格進入編輯模式,在那裏他們可以刪除記錄。從表中刪除單元格 - 提供的代碼
我想下面的方法做到了。我對麼 ?當我點擊編輯按鈕時,我會得到紅色圓圈和單元格上的刪除按鈕嗎?
2.)當用戶點擊它來調用以下方法時,我如何編寫編輯按鈕(UIBarbuttonitem
)的代碼?
3.)當我們刪除單元格時,我需要重新加載表中的數據。我爲此編寫了代碼,是否正確。 (我目前不在我的Mac上)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView beginUpdates];
[discardedItems addObject:[self.entries objectAtIndex:indexPath.row]];
[self.itemsMutableArray removeObjectsInArray:discardedItems ];
self.entries = [NSArray arrayWithArray:self.itemsMutableArray];
[self.tableView endUpdates];
[self.tableView reloadData];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
你用什麼itemsMutableArray的?你不能只是將條目作爲一個可變數組嗎? – SEG 2012-02-14 16:13:04
我將'entries'數組的內容複製到它,所以我可以輕鬆地刪除項目,然後將其重新分配給'entries'數組。 – shajem 2012-02-14 16:21:56