?舒心在TableView中的數(shù)據(jù)發(fā)生改變的時(shí)候,往往會(huì)發(fā)現(xiàn)UITableView中的數(shù)據(jù)沒有更新,通常需要滾動(dòng)后才會(huì)更新。
這個(gè)是因?yàn)樗闹乩L機(jī)制的問題。
一般情況下可以用下面這個(gè)方法解決:
在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)了一個(gè)給出的方法:
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
完整的可以這么寫:
NSRange range = NSMakeRange(section, 1);
NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
[self reloadSections:sectionToReload withRowAnimation:rowAnimation];
這樣就解決了section刷新的問題。