Why does my tableview automatically scroll after reloadData or reloadSection? - ios

I am using UITableViewAutomaticDimension in estimatedHeightForRowAtIndexPath. My tableViewCells are having large content in it. When i try to reloadData or reloadSection it automatically scroll up or down. I can not use reloadRow as my action can cause insertion/deletion/reload of certain number of rows in section.

Related

Dynamically update uicollectionview cell height

I am working on a quite complicated case
I have a nested UICollectionView
The outer UICollectionView A is for vertical scrolling,
and it's the first cell, is UICollectionView B, for horizontal scrolling.
It has been implemented perfectly, but now there is one more requirement
When scrolling the first cell to the second page, there is one more banner appeared on the bottom of the first cell.
Therefore I need to update the height of cell when scrolling.
If I try to call invalid layout when scrolling, it will be very low efficient. Are there any more methods to support it?
Solved.
First after received the data from the server, each cell height will be calculated and [collectionview reload] will be called.
Then after layouting the collectionview, the size for each cell is cached according to the indexpath.
To implement the 'realtime' resizing, the gesture will call a resizing function directing through a delegate, and directly modify the size cache and call [collectionview.layout invalidlayout].
It looks smooth.

UITableView: How to know when all the cells of TableView with dynamic cell heights are resized?

The problem I am facing is that when I send a data to UITableView then I send a command to scroll the table to bottom. If cell heights are constant then my scrollToLastCell takes to last cell but with dynamic cell heights it doesn't always takes to last cell.
I want to know is there any way when I can be sure that all cells of my tableView is finished resizing and then I trigger scroll to bottom?
In the Docs Apple states
Important
If your table view includes self-sizing cells, headers, or footers,
you must provide estimated heights for those items.
https://developer.apple.com/documentation/uikit/views_and_controls/table_views/estimating_the_height_of_a_table_s_scrolling_area
Given that, I'd suggest you to go ahead and use tableView(_:estimatedHeightForRowAt:) method

UITablleView insert rows animated without scrolling

I have implemented a TableView with multiple sections and a section headers and section footers in each section. When the user tapes one cell more cells are inserted in an animated fashion.
To implement this I update the data model and call
[self.tableView insertRowsAtIndexPaths:addedIndexPaths withRowAnimation:(UITableViewRowAnimationTop)];
On the top rows this works as expect: The aded rows animate and the content ofset of the tableview is constant. On the last cell the tableview scrolls either to the top of the previous section or to the top of the footer of the previous section.
Why does the tableview scroll when I insert rows? How can I prevent that scrolling while keeping the animation?
The main way around this is to not use insertRowsAtIndexPaths. Instead try using reloadSections in order to keep the animations.

UITableView dynamic cell heights - reload height for single row

I have a UITableView with rows of dynamic heights, many of which contain UITextViews. When the user starts typing in one of the textviews, I have the cells grow to accommodate the size of the textview content using the begin/endUpdates method. Using this method allows the cells to resize without losing keyboard focus on the textview, an important aspect of my app.
However, when I call begin/endUpdates, it reloads the heights for every cell that I have, and I was wondering if there was any way to only recompute the height of a cell at a particular indexPath while the user is typing. I want to do this because my heights for the other cells are expensive to compute as they have dynamic content. I know I could write some height caching code, but I was wondering if there was any method to only recompute the height of a specific cell or set of cells in a UITableView without losing keyboard focus / reloading the data content of that row?
I am using ios8, but will take an ios7/8 solutions.
Create of array of NSIndexPath's. If you have just one indexPath, add just this to the array, and use this method:
[self.tableView reloadRowsAtIndexPaths:[NSArray *array] withRowAnimation:UITableViewRowAnimationAutomatic];
but i think this method, will also hide the keyboard, never tried.
Doesn't seem like this is possible to do for only a single row. I ended up building a caching system for row heights so that at least it is faster to return heights for all cells.

how to change height cell in uitableview without reload data

I use UITableView and I want change the height of different cells. But I don't want use reload data for this because my table view contains UITextView which I edit in now and UIKeyBoard is up.
You're looking for the reloadRowsAtIndexPaths: method on the UITableView. It will trigger the recalculation of height (and subsequent redraw) of specific cells. It can even animate the adjustment so that you can do the update in real-time as the user is scrolling, such that the table view does not "jerk around" or "stutter step" while the heights are recalculated. I just implemented it successfully to do what you described.
Source:
Update UITableViewCell without reload
You can call beginUpdates && endUpdates, These will causes table cell heights to be recaluclated,
without reloading the entire cell
UIView.setAnimationsEnabled(false)
self.tableView.beginUpdates()
self.tableView.endUpdates()
// Re-enable animations
UIView.setAnimationsEnabled(true)

Resources