0

I am currently inserting cells in my UITableView with the following code:

[rottenTableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationTop];

It does the job correctly with the animation UITableViewRowAnimationTop. However, I would like to insert the cells with 2 animations at the same time (UITableViewRowAnimationTop and UITableViewRowAnimationFade). I tried the following:

[rottenTableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:(UITableViewRowAnimationTop|UITableViewRowAnimationFade)];

This code does not seem to animate insertion any differently than before. Any way to perform both animations?

n00bProgrammer
  • 4,261
  • 3
  • 32
  • 60
  • Have you tried splitting up your insert call into an insert call for the Top animation and an insert call for the Fade animation? – BHendricks Aug 14 '14 at 10:18
  • The reason `(UITableViewRowAnimationTop|UITableViewRowAnimationFade)` doesn't work is because `UITableViewRowAnimation` is an enum, not a bitmask. Use `[tableView beginUpdates]` and `[tableView endUpdates]`, and insert the rows on separate lines with different animations. – Tim Aug 14 '14 at 10:51
  • @Jeff, inserting same rows in two different lines will insert them twice, will it not? – n00bProgrammer Aug 14 '14 at 11:03
  • Sorry I misread your question, I thought you wanted to insert two different cells with different animations. It is not possible to use two of the predefined animations at once, it is an enum meaning they cannot be OR'd together. – Tim Aug 14 '14 at 11:11

1 Answers1

3

As far as I know, when you use -insertRowsAtIndexPaths:withRowAnimation: there could be only one animation type for a single cell simultaneously. But I could suggest using different animation types for different cells at the same time. For this you can use batch UITableView cell's updation via using beginUpdates/endUpdates. All the animations will fire at the same time, you can use it like this:

[tableView beginUpdates];

[tableView insertRowsAtIndexPaths:insertIndexPaths1 withRowAnimation:UITableViewRowAnimationRight];
[tableView insertRowsAtIndexPaths:insertIndexPaths2 withRowAnimation:UITableViewRowAnimationOTHER];

[tableView endUpdates];

For details check this: Batch Insertion, Deletion, and Reloading of Rows and Sections.
Also check this question about custom insertion animations: Can you do custom animations for UITableView Cell Inserts?

Community
  • 1
  • 1
MANIAK_dobrii
  • 6,014
  • 3
  • 28
  • 55