2013-04-28 64 views
6
[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft]; 
[self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight]; 

在上面的代碼中,如何在第一行的動畫完成後執行第二行?如何等待UITableView內置動畫完成?

我想這...

[self.tableView beginUpdates]; 
[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft]; 
{ 
    [self.tableView beginUpdates]; 
    [self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight]; 
    [self.tableView endUpdates]; 
} 
[self.tableView endUpdates]; 

這...

[self.tableView beginUpdates]; 
{ 
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft]; 
} 
[self.tableView endUpdates]; 
[self.tableView beginUpdates]; 
{ 
    [self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight]; 
} 

...但慢無論哪種方式動畫同時明確發生(真的明顯時動畫開啓)。

+1

你可以從這個http://stackoverflow.com/questions/3832474/uitableview-row-animation-duration-and-completion-callback – Iducool 2013-04-28 11:31:40

+0

它會出現,這是它是如何做需要幫助: HTTP:/ /stackoverflow.com/questions/2802146/callback-for-uitableview-animations – Dev2rights 2013-04-28 12:54:26

回答

22

謝謝Iducool指點我的另一個問題。

這個工作......

[CATransaction begin]; 
[CATransaction setCompletionBlock:^{ 
    [self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight]; 
}]; 

[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft]; 

[CATransaction commit]; 

我似乎並沒有要求UITableViewbeginUpdatesendUpdates

+4

如果加載的單元格包含'UIActivityIndi​​catorView',那麼完成塊永遠不會被調用。 – markturnip 2014-03-11 01:19:26

+4

在iOS 9上無法使用,請重新加載/ insertSections – tettoffensive 2015-10-09 23:25:47

+0

@markturnip如果您在單元格中有活動指示器視圖,是否曾經找到解決方案?我在這裏問這個。 http://stackoverflow.com/questions/39672868/reloading-table-view-cells-with-an-activity-indicator-view – 2016-09-24 23:31:25