Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detailTextLabel not showing initially

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.

like image 784
Bjinse Avatar asked Mar 30 '12 13:03

Bjinse


2 Answers

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".

like image 191
Bjinse Avatar answered Oct 13 '22 19:10

Bjinse


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.

like image 5
Jason Harris Avatar answered Oct 13 '22 20:10

Jason Harris