insertRowsAtIndexPaths with 2 animations - ios

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?

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?

Related

How to delete rows from UITableView without animation in IOS

I have an accordion type of UITableView that works but I just need to adjust the animation slightly. When a row is clicked a method is called that deletes the rows that are showing then adds the new rows to show. I don't want to animate the rows being deleted. I only want to animate the part when the rows are being added. I can use [UIView setAnimationsEnabled:NO]; to turn off the animation all together but I just want to turn it off for the deleting part.
[self.unitListTableView beginUpdates];
[self.unitListTableView deleteRowsAtIndexPaths:delete withRowAnimation:UITableViewRowAnimationTop];
[self.unitListTableView insertRowsAtIndexPaths:added withRowAnimation:UITableViewRowAnimationFade];
[self.unitListTableView endUpdates];
Any help appreciated.
Call reloadData on your table view and it updates without any animation.

How to add an UITextView in a resizable UITableviewCell

I need a text view inside of a resizable cell - the cell is resizing in real time, based on a specific timer/stopwatch. I can't simply put the text view inside the cell, because I'm resizing rows with reloadRowsAtIndexPath: every 10ms and that's causing the UITextView to resign first responder. I am trying to avoid calling becomeFirstResponder every time so what I did now was that I created an external text view and added it on top of the table view, so it basically only acts as if it was inside the cell.
Do you have any suggestions how else I could do this in a less hackish way?
Thanks, guys!
You shouldn't reload the table (contents) to resize. Just use:
[tableView beginUpdates];
[tableView endUpdates];
This will resize the cells but not reload the cells itself, so it should not resign the first repsonder.
[tableView beginUpdates];
[tableView endUpdates];
Call these methods if you want to perform operations simultaneously.
beginUpdates and endUpdates should be nested properly within the codes. These are the efficient methods that has been provided to us.

How to make a slide in UIViewTableCell

I am trying to create a UITableView so that When the user touches my normal UIViewTableCell another UIViewTableCell slides in from the right side with a new cell format. This new UIViewTableCell does not leave the UITableView.
The UIViewTableCells are 2 different custom Cells.
I was wondering if there is a way to swap one UITableViewCell that is of X type for another UITableViewCell that is of Y type with an animated sliding effect?
I've looked at the following code but I do not understand where do I place my Cell information.
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:myIndexPaths
withRowAnimation:UITableViewCellRowAnimationRight];
[tableView endUpdates];
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:myNewIndexPaths
withRowAnimation:UITableViewCellRowAnimationLeft];
[tableView endUpdates];
Any guidance on how to do this is highly appreciate it.
PS: I am not looking for a repo. I would like to understand how this is done.
Basically the way table view cell animation works is you update your data source (usually an array that you reference when providing cells to the table view), then call the animation methods. The table view calls numberOfRowsInSection and cellForRowAtIndexPath when you insert a cell, so it's important that they return the correct values.
In this situation, however, the number of cells remains the same so you can't use insertion and deletion. You can use cell reloading, however. Theoretically, every time didSelectRowAtIndexPath is called you would add to a list of tapped index paths that should display the new kind of cell. Alternatively, if you only want one of these special cells present at a time, you would use a single NSIndexPath variable. Then you would call
[tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationRight]; //or left
Then, in cellForRowAtIndexPath, you would check to see if the particular row requires a different type of cell, and you would return that new type there. That way, the code you need to present the new type of cell is insulated from the initializing of the new cell.
Hope this works for you!

Middle animation in grouped table view looks horrible

I've found similar question, but there is no answer (sorry, answer just doesn't work).
So I have grouped table and I want to animate content update instead of doing [tableView reloadData].
I do that by using this piece of code:
// Data source already updated here, but reloadData wasn't called
[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationMiddle];
[self.tableView endUpdates];
I uploaded 2 examples of the animation:
Plain: http://cl.ly/3u1M3l1w3V3J (slow motion)
Grouped: http://cl.ly/1O3Z2M280n0z (slow motion)
As you can see difference is huge.
I don't change my code at all, just change tableView style in the storyboard.
Does it men that there is no other way then subclassing UITableView and UITableViewCell and implement my very own animation using CoreAnimation?
Implementing your own animation with CoreAnimation shouldn't be necessary when it comes to animating the rows of the table.
UITableView supports much more advanced animations than simply reloading a section and I suggest that you take a look at them.
Since you are shuffling the rows in your videos you should take a look at moveRowAtIndexPath:toIndexPath: (on UITableView). You put the calls to it within beginUpdates and endUpdates.
By knowing the order before and after the re-shuffle you can move all the rows into their new places and have them slide into their correct place.
It will take some thinking to figure out where each row should go but it will be much easier than rolling your completely custom solution.

deleteRowsAtIndexPaths without animation

I got an app with a UITTableView. This table is updatable. And when in the next update the number of rows are less than in previous version, i implement the UITableView's method - deleteRowsAtIndexPaths.
I do it in this way:
[table beginUpdates];
[table deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
[table reloadRowsAtIndexPaths:indexPathsReload withRowAnimation:UITableViewRowAnimationNone];
[table endUpdates];
But when i implement this code there are animations. And this animation is really bad. A lot of black leaks. But i did write - withRowAnimation:UITableViewRowAnimationNone in both methods: delete and reload.
Why? How can i reload and delete rows without animation?
Usually the way this is done is by modifying the data source of the table, and calling reloadData on the table.
maybe you try to work with NSMutableArray (delete row by removeObjectAtIndex:indexPath.row) in TableView and reload the whole tableview by using [tableView reloadData] ?
You can try to make that "gesture" out of the table,and try reload table
Unlike what the name suggests *UITableViewRowAnimationNone* doesn't help at all.
Maybe setting the alpha on the cell works as suggested here. Not sure though.
problems with animation when deleting the last row of a TableView in ios7

Resources