美文网首页
tableview刷新 Section

tableview刷新 Section

作者: 一束橘子 | 来源:发表于2016-06-04 11:01 被阅读3088次

 舒心在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刷新的问题。

相关文章

网友评论

      本文标题:tableview刷新 Section

      本文链接:https://www.haomeiwen.com/subject/ztuldttx.html