1. 程式人生 > >iOS TableView的左劃刪除以及多個分割槽的刪除某一行的個人筆記

iOS TableView的左劃刪除以及多個分割槽的刪除某一行的個人筆記

  1. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
  2.     return YES; 
  3. -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath  
  4. {  
  5.     return UITableViewCellEditingStyleDelete;  
  6. }  
  7. /*改變刪除按鈕的title*/
  8. -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath  
  9. {  
  10.     return@"刪除";  
  11. }  
  12. /*刪除用到的函式*/
  13. -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath  
  14. {  
  15.     if (editingStyle == UITableViewCellEditingStyleDelete)  
  16.     {  
  17.     /*此處處理自己的程式碼,如刪除資料*/
  18.    [dataArray removeObjectAtIndex:indexPath.row]; ( NSMutableArray)
  19. //刪除對應分割槽中對應行的寫
  20. [[self.dataArray objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];
  21.     /*刪除tableView中的一行*/
  22.     [tableView deleteRowsAtIndexPaths
    :[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];  
  23.  //報錯則用 [self.tableView reloadData];
  24.     }