I've been trying to get my head around this all-too common problem of a expanding UITextView
inside a growing UITableViewCell
of a UITableView
and I'm nearly there except for one small thing.
I have a UITableView
that has a custom UITableViewCell
. My UITableView
is using the new iOS8 self-sizing dynamic cell height with the help of self.tableView.estimatedRowHeight
and self.tableView.rowHeight = UITableViewAutomaticDimension;
, that grows the cell height based on it's ContentView's auto-layout.
I can properly grow my UITextField
's frame and my UITableView
's cell height does indeed grow, but every time I called self.tableView beginUpdates
and the matching endUpdates
, my entire scroll view of the tableView forces a scroll to the top of the table view. I have a method that scrolls to the caret position, but as you can imagine, every time a new line is created in the UITextView, the UITableView scrolls to the very top and then to the caret position and it's janky as hell.
Anyone have any ideas? I can provide a video if necessary. Cheers, Mike
Scrolling to the top of a UITableView can be a useful feature depending on the type of app that you are making. If you have a tableview with hundreds of cells it can be annoying scrolling to the top of the tableview once you have scrolled far down the tableview.
Table views are more versatile than you might think. For example, many developers make their life harder using a scroll view when a UITableView would be a better choice. Finally, architecture is crucial for table views.
The first scrolling action we’ll add to our action sheet is scrolling the first row in the tableview. Note that this action is different than scrolling to the top of the tableview. If the tableview has a header then scrolling to the top would scroll to the top of the header. We’ll do that action later.
The cells of UITableView are instances of UITableViewCell or its subclasses. It is the table view that adds, removes, and arranges cells in its view hierarchy. Table views reuse cells that go out of the screen to display new elements, so that:
This got me as well, and it looks like self.tableView.estimatedRowHeight
is the problem. When I made the estimate large enough the problem stopped happening.
I added this instead and it's working well so far:
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With