UITableView beginUpdate and endUpdate on last cell reloads tableview - ios

I have a tableview with expand-collapse cells. Whenever a cell is selected, I simply call :
tableView.beginUpdate()
tableView.endUpdate()
This in turns recalls the heightForRowAtIndex method, where I set the new height and this seems to show expand-collapse behavior.(without reloading the cell).
ISSUE: When I tap on last cell(or last 2-3 cells), after tableView.beginUpdate()
tableView.endUpdate(), the table reloads itself. I have no clue why it is behaving like this.
It seams like since there is no space at the table's bottom to expand a cell, it's reloading itself.
Can someone throw light on this?

estimatedHeightForRowAt works always.

Related

ScrollViewDidEndDecelerating gets called every time when I select cell

I know that it would be repeated question but I really stuck on it. My first CollectionView’s each cell has another collectionView as a subview. My first CollectionView has three cells with same width and height and my Second collectionView has 27 cells. I want to show edge of next and previous cells at second cells of the first collection view and got it using the ScrollViewDidEndDecelerating delegate method of the uiscrollview but the problem is the he gets called even simple touch on any collectionview item. Please help me, how do I get rid of this shit?
If anyone wouldn’t get my point I can share code as well.

Weird issues when reloading data (iOS)

I have a collectionView, called parentCollectionView, which scrolls horizontally. Inside each reusable cell is a collectionView, called childCollectionView which scrolls vertical.
I am having a strange issue. When I reloadData() on the parentCollectionView, the cell will glitch/flicker for a fraction of a second, and if you are scrolled down, it will load the childCollectionView from the top. The weirdest thing, is that it only happens the first time you call reloadData() on the parentCollectionView. Everytime after that, there is no flickering, and doesnt force you to the top. And when I ditch the reloadData() method and use reloadSections/IndexPaths it will for load from the top everytime.
What the heck is going on?
I didn't call reloadData on the parentCollectionView. Instead, I called reloadData on the childCollectionViews that are visible and set the delegate/datasource to nil, to cells that have been deallocated (in prepareForReuse).
It seems as reloading the parentCollectionView via reloadData() is redrawing everything.

UITableView cells disappearing, wrong cell passed to didEndDisplayingCell

I'm seeing another case of UITableView cells disappearing unexpectedly when scrolling, but none of the similar questions & answers here I've seen really fit what I'm seeing:
I scroll down until my top cell is removed and tableView:didEndDisplayingCell:forRowAtIndexPath: is called for it, then scroll back up until it's shown again. During the scroll up, the tableview is trying to remove the cells that were shown while scrolling down, however its actually removing the wrong cells.
As I'm scrolling up, tableView:didEndDisplayingCell:forRowAtIndexPath: is getting called with the correct index path, one it should be removing, but a cell that corresponds to a different index path. The cell and index path passed to the didEndDisplayingCell don't match.
This is in a small modification of the XLForm example project from https://github.com/xmartlabs/XLForm in which I've added a custom cell. What's weird is that if I make my custom cell the same height as the table's normal height (44) then this doesn't happen. Only when my cell is taller (64, with this value returned from tableView:heightForRowAtIndexPath: and tableView:estimatedHeightForRowAtIndexPath:).
I'm seeing this happen when running in the simulator, iOS versions 8.4 and 9.2.
I haven't been able to figure this out. I don't think I have any of the bugs that have caused others to have disappearing cell syndrome, but even if I do, I don't see how or why the tableview would be calling didEndDisplayingCell with cell and index path that don't match. Does anyone else have a clue what's happening?

iOS dynamic height cell in tableview- issue with row 0 and 7

I am having a tableview in which I am displaying my data. As you can assume from the title, these cells are dynamic in their content, and so should their height be. Actually I got it working, but I have a strange issue with the row 0 and 7. These 2 rows take my entire screen, but when I scroll past them and go back again everything is fine. I am not sure but the 7. cell must be among the first cells that are being "dequed" when I scroll down. But as I said, this is just the first time they are being displayed, when I scroll again to one of them, everything is looking good (when filling the tableview with new data it is also fine).
I tried to reload the tableview twice when it is being populated for the first time, but without success. The presentation of the first cell I have fixed calling : self.tableView reloadAtIndexPaths ... when the table is being populated for the first time,
and it worked, it has the height it should have regarding its size. But I still have the issue with cell number 7 (the above fix does not work for this cell, I assume because it is not being displayed at that moment)
I am not using any fancy height calulation, just the iOS 8 feature:
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 80
Is there a method, fix with which i can force the tableview to draw the cells again ?
Thanks
Cell size is calculated from constrains. So I assume there is something wrong with those or with data during computation.
try this:
in tableview cell subclass use -prepareForReuse method to clean cell data as before reuse.

Monotouch: Force UITableView to recalculate height of each cell without reloading data

I have a custom cell created using OwnerDrawnElement with autoresizeable UITextView in it.
When text changed there should be appropriate layout redraw and cell height recalculation.
The problem is how to preserve keyboard opened.
There is a method inside UITableView - ReloadRows which actually helped me in some fashion.
I can't call it for my cell because it is the first responder and can't I cant resign it.
But when I call it for another cell my cell is getting resized as I wanted but I have unnecessary another cell redraw.
So I wonder what method is called to relayout UITableView NOT reload data?!
The same method is probable called when you scroll up and down, cells become visible and height is recalculated.
I've tried standard SetNeedsDisplay(), SetNeedsLayout(), ReloadInputViews(), LayoutSubviews(), but it didn't do the same. Maybe I need use them somehow differently. I've tried to call them for cell and whole tableview objects.
I've looked into ReloadRows method and found out that it calls some API stuff:
Messaging.void_objc_msgSendSuper_IntPtr_int(base.SuperHandle, UITableView.selReloadRowsAtIndexPathsWithRowAnimation_, nSArray.Handle, (int)withRowAnimation);
So it doesn't what method forces tableview to recalculate height of each cell without reloading data either.
Can you help me with that?
Try to update cells frames, then call UITableView's empty update block:
tableView.BeginUpdates();
tableView.EndUpdates();

Resources