开发者

table reloadData not working

开发者 https://www.devze.com 2023-02-09 08: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 aggain ,i want when i

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 aggain ,i want when i delet the row tableview should rload the data... any idea ?

-(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 开发者_JAVA百科delHaditid = delHadit.haditid;
    [dbmethods deleteBookMark:delHaditid];
    [dbmethods release];    
  }
  [self.table reloadData];//its not working reload data...
  [table endUpdates];
}


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];
}


What is self.table? Is it your class variable for your UITableView? You should note that you can also reference the UITableView directly since it is passed into that method as tableView. I dunno if your table variable isn't setup correctly (through Interface Builder) or what, but I'd try using the tableView variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号