关于UITableView界面刷新

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

原文地址:https://www.cnblogs.com/xiaoxiaoyublogs/p/5485482.html