3 回答

TA貢獻1820條經驗 獲得超2個贊
在啟動期間(-viewDidLoad or in storyboard)執行:
self.tableView.allowsMultipleSelectionDuringEditing = NO;
覆蓋以支持表視圖的條件編輯。如果您要返回NO某些項目,則只需要實現此功能。默認情況下,所有項目都是可編輯的。
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
}
}

TA貢獻1712條經驗 獲得超3個贊
此代碼顯示了如何實現刪除。
#pragma mark - UITableViewDataSource
// Swipe to delete.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_chats removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
(可選)在初始化覆蓋中,添加以下行以顯示“編輯”按鈕項:
self.navigationItem.leftBarButtonItem = self.editButtonItem;
- 3 回答
- 0 關注
- 945 瀏覽
添加回答
舉報