Currently I have a UITableView
with a resizing UITextView
in it. The cell is resizing automatically using beginUpdates
/endUpdates
, but when it does it the table view stutters (See the gif below).
The end result is a UITableViewCell
that has a textview in it that resizes based on it's content. Here is the code within the custom UITableViewCell
class that causes the UITableView
to update itself.
- (void)textViewDidChange:(UITextView *)textView {
// This is a category on UITableViewCell to get the [self superView] as the UITableView
UITableView *tableView = [self tableView];
if (tableView){
[tableView beginUpdates];
[tableView endUpdates];
}
}
Here are the things that I have already tried:
Get the current contentOffset
and resetting it after the endUpdates
but didn't work
Disabling scrolling on the UITableView
before updates and then enabling afterwards
I tried returning NO
always from - (BOOL)textViewShouldEndEditing:(UITextView *)textView
My UITableView
cell height is using UITableViewAutomaticDimension
. Any other ideas or thoughts are welcome.
Here is a sample of what it looks like:
I am not looking to use any libraries so please no suggestions for that.
Thanks
Edit: Solution
Found Here: I do not want animation in the begin updates, end updates block for uitableview?
Credit to @JeffBowen for a great find (although hacky it is workable and allows me to still implement the UITableViewDelegate
methods for supporting iOS 7). Turn animations off prior to performing update and then enable after update to prevent the UITableView
from stuttering.
[UIView setAnimationsEnabled:NO];
[tableView beginUpdates];
[tableView endUpdates];
[UIView setAnimationsEnabled:YES];
If you don't need to use the Delegate methods and want a less hacky solution for iOS 8+ only then go with @Massmaker's answer below.