uitableviewcell corruption (saw from the bottom) on selection - ios

I get this mini-horror sawtooth artifact at the bottom
of the cell on UITableViewCell selection
is there any cure?
ios version agnostic, happens on 9 and 10
both real devices and simulator
UPD: using first answer here: UITableView separator line disappears when selecting cells in iOS7
switching from blue selection style to style none masks this issue,
not sure if feedbackless cell selection style would be acceptable
for my employer though.

First check is height for your cell is correct or not.
If using autolayout and height is correct then verify the constraint for this label with proper hugging priority and compression resistance.
If using autolayout, also make sure you have set the preferredMaxLayoutWidth for your label
Also call layoutIfNeeded for your cell [cell layoutIfNeeded]

The minimal sufficient change to kill the artifact was to change
the default background for the label from default to white
to match the cell background.
In any event killing transparency fixed this, whatever that was.
A bug in GPU or GLES driver or higher up the stack. Whatever.
UPD20171024: closeViewAndMoveMapToPlase: is the culprit in another table.
This looks like a single symptom multiple causes issue.

Related

UITableViewCell prevents UILabel from expanding height

I have a TableViewController with a custom UITableViewCell containing a single UILabel. The label will receive variable lengths of text, and should resize in height accordingly. I want to use auto layout, iOS10++.
However, it seems that the cell is preventing the label from expanding its height.
I have constraints on the label to pin top, bottom, left and right to the cell's contentView.
The label number of lines = 0, and is set to line break mode = WordWrap.
I have set the self.tableview.rowHeight to UITableViewAutomaticDimension, and have set the estimated row height to various sizes with no success.
I have increased (and decreased) the label's content hugging priority and and the vertical compression resistance, but this has no effect.
This sounds like a duplicate of so many other questions, but none I have read has solved my problem.
Some clues I have noticed:
1) If I remove the label's bottom constraint, the label expands correctly, but (of course) the cell doesn't expand, so the label cannot be fully seen after it expands below the bottom of the cell. So I conclude that the cell is preventing the label from expanding.
2) if I rotate the tableview to landscape and back to portrait, the first cell expands correctly. So something that occurs during the rotation solves the problem at least for the first cell, and also proves that the cell and label can expand as required.
I feel something is not right, but cannot figure it out. I am very close to going back to the old version of calculating the height manually and returning it in heightForRowAtIndexPath delegate method.
I would appreciate any suggestions. Thanks in advance.
I finally figured it all out.
In summary, I was configuring the cell (including setting the label's text) in tableView willDisplayCellAtIndexPath...
But it seems (obvious really) that for the autoresizing to work, the cell must be configured in tableView cellForRowAtIndexPath.
Moving the configuration into cellForRowAtIndexPath and suddenly everything started working perfectly.
Hope this helps anybody who has the same problem. I struggled with it for days.

TableViewCell height incorrect in iOS 8 with appearance proxies

In iOS 8 our table view cells are first displaying with the height from the xib file rather than with the height resulting after the appearance proxies are applied. For example, the fonts from the appearance proxy are present, but the label height is taken from the xib file. When the view is scrolled off and back on, the height is correct. This problem does not occur in iOS 9.
Any ideas how to address? We've tried setNeedsLayout followed by layoutIfNeeded and every other recommendation we've found on SO. We've also tried setting estimatedRowHeight.
The only workarounds we know of are to either ensure that in the xib file all the cell elements are the same height as their themed counterparts or to explicitly set the cell height through tableView:heightForRowAtIndexPath. Both of these cause the loss of much of the benefit of appearance proxies.

UILabel not respecting contraints after scrolling (label inside a xib, dequed as a uitableviewcell)

This is the craziest problem I've ever faced in iOS development. Basically I have a xib file:
This xib file is loaded as a row in a UITableView. In this xib file I have an UILabel ("Texto do comentário"), that is a multiline uilabel and will expand according to its content. To do so, I've added the following constraints and content hugging:
And all this actually works fine when I run and replace the content with a big text. This is how it looks like:
OK, now it begins the weird things, if I scroll up to the other cell (that uses the same xib file), the text view expanded its width and height in a way that doesn't respect my constraints:
Now if I scroll back to my cell that was working fine before, it has the same problem, the uilabel's width and height are not respecting my constraints anymore:
I've tried to inspect what actually happens to the constraints, if they are being ignored by some reason, and here is what I've found out. Both the constraints of my uilabel that has the right size and the ones in the uilabel that has the wrong size are the same.
I'm really starting to thing that this an iOS bug. Thank you in advance for your help
After trying, at least everything. The fix I found is to use UITextView instead of UILabel. This fix made me be sure that this is a UILabel bug.
I would say the problem you have is that you changes the Content Hugging Priority and Content Compression Resistance Priority values, which will make the UILabel not resize as you would expect.
You could try resetting the values to the default ones and if your other constraints are correct, the height of the label and of the cell should be calculated correctly.
Probably the UITextView worked because you did not change the default values for these properties.
Hope this helps.
This looks like another bug I previously encountered with self-sizing cells in a table view. Originally, I worked around it by explicitly setting the preferredMaxLayoutWidth of my cell's labels but I then discovered that sending an -updateConstraintsIfNeeded message to my cell in -tableView:cellForRowAtIndexPath: also worked around the issue without needing to set the preferredMaxLayoutWidth.
Hope this helps.

Custom UITableViewCell - UILabel not aligned properly

I am creating a custom UITableViewCell using the Storyboard editor. I've got several components in this cell, but the biggest is a UILabel that is displayed at the top. This label should be left-aligned, however I'm finding that when I run the app in the simulator to test, the text is centered. I've tried specifying the alignment manually, but it always centers itself.
Is there something I need to do to get this working properly in a custom UITableViewCell? I've never encountered anything like this before.
Try using Debug->Color Render layers in the simulator to see if your text is actually centered, or the UILabel moved. Try removing the outlet if any, to prevent anything from tampering with it and see if it helps diagnose.
If the colored layer is offset, make sure you added proper constraints to the label (or autoresizing masks). Anchor it to at least left and top and leave the other 2 sides free.

UITableViewCell wrong height in initial display

This isn'an a question, just a results log on an issue I had with XCode 4.5 storyboards and dynamic height UITableCell with a UILabel.
The issue was; the initial display of a cell would only show part of the resized UILabel contents, and that the visual UILabel was not resized. It would only display correctly after scrolling off the top of the Table and back down.
I did the calculations in hieghtForRowAtIndexPath and sizeToFit the UILabel in rowAtIndexPath. The sizes where coming up ok in debug, but the device was not updating the display with the correct size and UILable.text value.
I had created the dynamic UITableCell in a storyboard. However, I had set the width and height to a nominal value (290x44). It turns out, this was causing my issues.
I set the width and height to zero (0) in the story board, and everything started working correctly. (i.e. the UILabels displayed at the correct size with full content).
I was unable to find anything online on this issue, except for some references to creating the custom table cell with a frame of zero. Turns out, that was really the answer (for me).
I ran into the same problem and solved it by simply unchecking "Use Autolayout" in storyboard. You might want to give it a try.
I was unable to find anything online on this issue, except for some references to creating the custom table cell with a frame of zero. Turns out, that was really the answer (for me).

Resources