tableView左滑刪除功能


實現三個代理方法即可

 

 

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
    return @"刪除";
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{   if (!indexPath.section) return UITableViewCellEditingStyleNone; // 第一組家和公司不提供左滑刪除功能
    return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
        [self.commonPlaceArray removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:@[indexPath]
                              withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView reloadData];
    }
}

 

上面說漏了一點,就是有個代理方法是開啟允許進入編輯狀態的,這樣才可以進行左滑或者添加的其他操作,注意當你左滑后,沒有把這個cell滑回去,這時候如果你在返回上一個頁面可能會崩潰,這個時候你需要在viewWillDisappear方法中將這個編輯狀態置為NO,好的,現在終於操作流暢了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM