How to add an UITextView in a resizable UITableviewCell - ios

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.

Related

iOS : How to reload a UITableView with a lot of cells without lagging the App?

I have a lot of cells (around 3000 cells) that I need to reload constantly. I was wondering if there is currently a way to reload it faster without it lagging the App. I do the typical [tableview reloadData]; Any tips or suggestions are appreciated.
Don't implement tableView:heightForRow: in your delegate or it will slow down considerably as it recalculates every row. iOS checks to see if you implement that method and if you define it the OS changes its table height calculation from a simple multiply to a loop over the cells.
Since you have not provided context or code to show where you call [tableview reloadData];, I can only talk in generalities.
I am going to assume in your 3,000 rows possible 20 are displayed at a time.
Here is the sequence of events or actions that needs to occurs
A row gets update
Check if row is visible: indexPathForVisibleRows
If row is not visible, nothing to do
If row is visible, then following actions should be taken
[tableview beginUpdates]
[tableview reloadRowsAtIndexPaths...]
[tableview endUpdates]
Reload only visible cells if you have consistent number of items, otherwise use insert/delete methods to add cells to tableview.
When making a reloadData for your tableView, tableView:heightForRow: delegate function make a height recalculation of every row.
My solution is to save the heights for your cells already calculated (create an NSDictionary that contains all row heights. exp. create a NSDictionary with keys is the id of object that will be show on the cell and the value is the height).
When tableView attempt to recalculate the height of each cell, it will check if we have already a saved entry in your dictionary with this key (id of object), and tableView:heightForRow: will return this value if found.
I am using this solution in my chat app, and I noticed a performance increase.
Good luck.

insertRowsAtIndexPaths with 2 animations

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?

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 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!

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