table reloadData not working

前端 未结 2 527
不思量自难忘°
不思量自难忘° 2021-01-28 05:17

i am using following code to delet a row from tableview as well from db , the row is delted from the db at once but its not delted from the tableview till i back back and th chk

2条回答
  •  臣服心动
    2021-01-28 05:34

    Include this line,

    [self.allBookMarks removeObjectAtIndex:indexPath.row];
    

    EDIT:

    The problem is not with reloadData, the problem is that you are not updating your datasource (self.allBookMarks). Update the values into self.allBookMarks then reload the table.

    Edited Code

    -(void) tableView:(UITableView *)tableView
    commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
    forRowAtIndexPath:(NSIndexPath *)indexPath 
    {
        [self.table beginUpdates];
    
      if (editingStyle == UITableViewCellEditingStyleDelete) 
      { 
        Hadits *delHadit = [self.allBookMarks objectAtIndex:indexPath.row];
        dbAccess *dbmethods = [[dbAccess alloc] init]; 
        NSInteger delHaditid = delHadit.haditid;
        [dbmethods deleteBookMark:delHaditid];
        self.allBookMarks = [dbMethods getAllBookMarks]; 
        [dbmethods release];    
      }
      [self.table reloadData];//its not working reload data...
      [table endUpdates];
    }
    

提交回复
热议问题