?舒心在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刷新的問題。