?舒心在TableView中的數(shù)據(jù)發(fā)生改變的時候先鱼,往往會發(fā)現(xiàn)UITableView中的數(shù)據(jù)沒有更新渴析,通常需要滾動后才會更新啄寡。
這個是因為他的重繪機(jī)制的問題拾弃。
一般情況下可以用下面這個方法解決:
在viewWillAppear中加入這兩句:
- (void)viewWillAppear:(BOOL)animated{
[self.tableView reloadData];
[self.tableView reloadSectionIndexTitles];
}
這兩句可以起到刷新UITableViewCell的作用,但是如果section的數(shù)據(jù)發(fā)生了改變羡疗,則沒有被刷新染服。
后來在
http://stackoverflow.com/questions/8306792/uitableview-reload-section
發(fā)現(xiàn)了一個給出的方法:
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
完整的可以這么寫:
NSRange range = NSMakeRange(section, 1);
NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
[self reloadSections:sectionToReload withRowAnimation:rowAnimation];
這樣就解決了section刷新的問題。