I am using a static UITableview, set up in a storyboard. For some cells (Style = Right detail) I set the detailTextlabel.text in viewWillAppear like this:
self.recentProductsCell.detailTextLabel.text = description;
For this cell the label does not appear. If I NSLog the text it shows to be OK. I checked that the detailTextLabel is not hidden. I did not change any of the other properties in storyboard. The cell has a detailDisclosure accessory, but setting it to something else did not help.
Then the strange thing: If I run and the detailTextlabel does not show, I select the row by tapping on it and moving my finger. From then the detailTextLabel does show! Even when hiding and reshowing the view, the label keeps visible. Resetting and setting it in code however, makes the label disappear again.
Could I be doing something wrong, or is this a bug?
Edited: Checked in both 5.0 and 5.1, same behavior. I found an ugly workaround by Selecting and Deselecting this row in code in the viewWillAppear. So I added:
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
[self.tableView deselectRowAtIndexPath: [NSIndexPath indexPathForRow:3 inSection:0] animated:NO];
It works, but I can see the row being selected and deselected. So I also changed the selectionStyle, but now this row flickers when the view is shown.
Extra comment: In the same viewWillAppear, I set the detailLabel of other static cells, and they show up just fine.
I did find when the detailLabel did not show up, not why, IMHO it's a bug.
If the previous value for the detailLabel.Text was nil or an empty string, the detailLabel does not show up after setting it to the new value. If I set the detailLabel to anything else than nil/empty (initially), and then set it to something else, the new value correctly shows up.
The reason for not showing is probably more complicated then just being empty before, but in my case this solves my problem. I can probably show the detailLabel in the background colour if I want it to be "empty".
I've got a duplicate of this issue. Same configuration - static cells in a storyboard, but with left detail cells. I also see the issue where touching the cell makes it visible.
I worked around this by setting the initial detail label content in the storyboard to a single space. After setting the actual detail label content in code, I send a sizeToFit message to the detail label.
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