假设您只想在用户选择同一单元格的同一行三次时才删除该行。
创建另一个变量lastSelectedRow
以保留最后选定的行。(在实现线下创建)
@implementation myViewController
{
NSInteger = lastSelectedRow;
}
接下来,您应该验证该行是否等于最后选择的行,递增并检查是否必须删除该行:
for (NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows) {
// If the last selected row is the same, increment the counter, else reset the counter to 1
if (indexPath.row == lastSelectedRow) count++;
else
{
lastSelectedRow = indexPath.row;
count = 1;
}
// Now we verify if the user selected the row 3 times and delete the row if so
if (count >= 3) [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
NSLog(@"rowCount %d indexPath.row %@", count, indexPath);
}
希望能帮助到你。