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

Nel codice precedente come si esegue la seconda riga dopo che l'animazione dalla prima riga è stata completata?Come posso attendere fino al completamento di un'animazione incorporata di UITableView?

Ho provato questo ...

[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]; 

e questo ...

[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]; 
} 

... ma in entrambi i casi le animazioni sono chiaramente accadendo allo stesso tempo (e davvero evidente quando lento le animazioni sono attive).

+1

Si può prendere l'aiuto di questo http://stackoverflow.com/questions/3832474/uitableview-row-animation-duration-and-completion-callback – Iducool

+0

Sembrerebbe questo è come è fatto: http://stackoverflow.com/questions/2802146/callback-for-uitableview-animations – Dev2rights

risposta

22

Grazie Iducool per avermi indirizzato all'altra domanda.

Questo ha funzionato ...

[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]; 

non mi sembra di richiedere UITableView s' beginUpdates e endUpdates.

+4

Se la cella caricata contiene un 'UIActivityIndicatorView', il blocco di completamento non viene mai chiamato. – markturnip

+4

non ha funzionato per me su iOS 9 con reload/insertSections – tettoffensive

+0

@markturnip Hai mai trovato una soluzione a questo se hai una visualizzazione di indicatore di attività nella cella? Ho chiesto questo qui. http://stackoverflow.com/questions/39672868/reloading-table-view-cells-with-an-activity-indicator-view –