Ho una visione tabella con due righe in una sezione, cioèIn una vista tabella iOS, come deve essere spostata una riga in una nuova sezione?
---
Row A
Row B
Se voglio animare riga 1 in una nuova sezione, cioè l'essere risultato finale:
---
Row B
---
Row A
come dovrebbe questo essere realizzati? Quello che ho provato già è:
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow: 0 inSection: 0]] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView insertSections:[NSIndexSet indexSetWithIndex: 1] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
Tuttavia, in iOS 8, almeno, la riga anima fuori, ma poi la nuova sezione è un rendering (cioè bianco, nessuna riga bordo inferiore) fino a qualche tempo dopo quando qualcosa innesca un ridisegno e ritorna.
[self.tableView beginUpdates];
[self.tableView moveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] toIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
[self.tableView endUpdates];
che solleva un'eccezione:
Invalid update: invalid number of sections. The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (1), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).
E:
[self.tableView beginUpdates];
[self.tableView insertSections:[NSIndexSet indexSetWithIndex: 1] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView moveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] toIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
[self.tableView endUpdates];
che solleva l'eccezione:
cannot move a row into a newly inserted section (1)
devo solo non animare a tutti e ricaricare il tavolo intero?
Forse è meglio separare il livello dati con il livello di visualizzazione. Cioè Carica i tuoi dati con l'origine dati progettata, magari array 2-D, quindi modifica l'array e chiama tableView.reload – zcui93