2011-03-14 44 views
6

後執行reloadSections我需要執行需要[self.tableView endUpdates]做動畫

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { 
// The fetch controller has sent all current change notifications, so tell the table view to process all updates. 
    [self.tableView endUpdates];  
} 

做動畫

[[self tableView] reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone]; 

後。

我想這樣做,因爲我需要重新配置部分中的某些單元格,當從該部分刪除單元格時。這是因爲該部分的第一個和最後一個單元格的背景不同於它們之間的單元格。單個單元格具有不同的背景。 如果我不重新配置該部分中剩下的單元格,可能會導致一個不協調的視圖。

controllerDidChangeContent期間調用reloadSection過早並崩潰,因爲無法再找到單元格。

回答

15

如果你想通過1個多參數與延遲的方法,敷在自己的方法,該方法調用:

- (void)reloadSections { 
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] 
     withRowAnimation:UITableViewRowAnimationNone]; 
} 

然後,當你要重新加載:

[self performSelector:@selector(reloadSections) withObject:nil afterDelay:.2]; 
+0

我試圖把在該行之前我endUpdates說法,卻得到了一個 「 'NSInvalidArgumentException' 的,理由是:「 - [UITableView的reloadSections:]:無法識別的選擇發送到實例」 味精。 – P5ycH0

+0

糟糕,這是因爲reloadSections需要2個參數,而不是1 ...編輯。 – GendoIkari

+0

謝謝,這解決了我的問題! – P5ycH0

2

什麼對這個?

[CATransaction begin]; 

[CATransaction setCompletionBlock:^{ 
    // animation has finished 
}]; 

[tableView beginUpdates]; 
// do some work 
[tableView endUpdates]; 

[CATransaction commit];