在TableView中的数据发生改变的时候,往往会发现UITableView中的数据没有更新,通常需要滚动后才会更新。

这个是因为他的重绘机制的问题。

一般情况下可以用下面这个方法解决:

 

在viewWillAppear中加入这两句:

 

- (void)viewWillAppear:(BOOL)animated{

    [self.tableView reloadData];

    [self.tableView reloadSectionIndexTitles];

}

 

这两句可以起到刷新UITableViewCell的作用,但是如果section的数据发生了改变,则没有被刷新。

后来在

http://stackoverflow.com/questions/8306792/uitableview-reload-section

 

发现了一个给出的方法:

- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation

 

完整的可以这么写:

NSRange range = NSMakeRange(section, 1);

    NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];                                     

    [self reloadSections:sectionToReload withRowAnimation:rowAnimation];

 

这样就解决了section刷新的问题。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2022-01-10
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案