UITableView cells disappearing, wrong cell passed to didEndDisplayingCell - ios

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?

Related

IOS last tableViewCell separator is missing

I have tableView with multiple cells (without sections).
I add non-empty tableFooterView to the tableView. After that the last cell separator is not shown. Also when tableView is scrolled, separator sometimes appears or disappears. It happens both on simulator and on the device.
I've checked Debug view hierarchy and found the following:
It is very strange. Penultimate cell separator is duplicated there but the last separator is single. May be the problem is somewhere there?
I've also checked it's properties:
All I found as solution is to add empty tableFooterView but I need it to be filled.
How to make the last separator be always visible (also when scrolling)?
I know you can get away without using actual separators, but adding one pixel line in the bottom of the cell. But I'm not a fan of this approach.

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.

Changing the height of the row causes issues

I got a problem with the Tableview-Cells in iOS.
I got a tableview with custon cells in it. I wanted to lower the height of the cells.
The row height in the tableview was set to 105, I changed it to 55 (the actual height of the custom cells wich are provided as xib-files).
So far, so easy, but now to my problem:
After the tableview loaded, it showed only one entry, but all the other entries aren't shown. If I scroll down and up again on the other hand, the previously hidden entries are shown.
I tried to work a little with the heigh-values in the tableview-options, and as I increase the heigh the more of a cell is shown on the first loading, but its never a complete cell until I set it to 105 again. Scrolling fixes the broken entries.
There is by far enough size on the screen and the cells height is exactly 55.
Has anyone here has an idea what could cause that problem?
As allways, thanks for any help.

UITableView cells are unloaded too early after reordering

I've recently built in reordering into my UITableView but there's a nasty bug I'm experiencing after reordering the cells. The bug only occurs after a cell has been reordered: When scrolling the table view up, the cells visible at the bottom of the screen sometimes simply disappear while scrolling. It seems as if the cells are unloaded too early. This only happens when scrolling up. When scrolling down the bug doesn't exist. The cells that randomly disappear also re-appear when scrolling down once their empty space leaves the screen. Here's a screenshot of this issue:
I'm pretty sure that my data source isn't the problem because:
When reordering a cell my data source updates as well
I've checked the table view with Spark Inspector and the missing cells aren't simply hidden or empty but they just don't exist, there is no cell at all where the empty spaces are.
After scrolling around the cells re-appear, the cells randomly appear and disappear
It must be some bug or issue in UITableView, but I may also be wrong with that assumption. Maybe somebody has already faced this problem and can help me out now ;) I'm waiting for your answers :)
Edit:
I just checked the -tableView:didEndDisplayingCell:forRowAtIndexPath: delegate method and the cells are really unloaded normally and that method is called, even though the cells are still visible on the screen!
Edit (2):
I now know that the issue only occurs when my table view has a header view. It doesn't matter if I use the default header or a custom one, but whenever I use a header view I also get the bug. When I don't use a header it works just fine. Thats really strange
Note: I'm testing this on iOS 6.1.2

Issues regarding dynamic resizing of label and row heights (iOS)

Context:
Building an app that populates a table that takes in data from a asyc json dump.
The cells are of a custom class (I defined). The main label in the cell can be very long.
It is "placed" in storyboard within a prototype cell but customized via code (pretty standard stuff).
Labels are resized in cellForRowAtIndexPath and rows are resized via heightForRowAtIndexPath -- rows are resized by forcing a call to cellForRowAtIndex like Massimo's answer here
So per the question at hand - I've noticed some interesting (bad) things that happen.
First issue: When the table loads, the rows and labels are dynamically resized correctly! Great! However, when I scroll down and then scroll back up, the label heights will be incorrect -- (for example) the first row was correct at loading. Then when I scroll down and then scroll back up to see it again, it will be truncated. Specifically, the row size will be fine but the label height will change and become truncated to 2 lines only. Wondering if this is because I did both storyboard and coding to customize the cell. Anybody see this before?
Second issue: When I scroll down, while the rows are sized correctly (large), the labels are short (truncated.) Wondering if it's some reverse of the above "potential answer".
"potential answer" is that the rows are all calculated and stored "up front" so that scrolling down/then back up doesn't affect it. However, when cells go "out of view" and are dequeued then when they re-viewed (scroll down/then back up) it will rely on the storyboard.(inappropriately?)
All three of your issues are symptomatic of returning the wrong height in heightForRowAtIndexPath. In my data model classes I have a calculateHeight method that I call in heightForRowAtIndexPath. The model also caches the answer so it doesn't have to recalculate it after the first call. The cell class uses the model's calculated height to layout its subviews.
"ANSWERED" by deleting the prototype cell from the storyboard and making them fully in code, the issue went away. The fundamental workings are still not understood (ie. the interactions between storyboard vs. code when cells are put queued and then viewed again)

Resources