The Hit List Diary #11 – Right Detail table cells

We’ve been using a fairly vanilla “Right Detail” style UITableViewCell (UITableViewCellStyleValue1 if you care about such things) for displaying the name of a list, and the number of tasks within it.

Under iOS 8, the cells started to behave a bit strangely. Quite often the detail label — the count in our case — would go missing. Tapping the cell to highlight it would cause that label to appear back on screen as expected.

Poking around in the debugger showed that the label was present in the cell as expected, and had the correct string value, but for some reason its width was 0, so nothing appeared.

OK then, perhaps I can trigger an extra layout pass to work around the problem? Nope, no dice. Seems the table cell relies on more than just .needsLayout to decide if its labels should be adjusted.

While hunting around the internet for ideas on this, I did come across a rather informative Stack Overflow answer. The problem seems to be that if the detail label isn’t already part of the cell’s contentView at layout time, the width gets miscalculated.

The author of that answer recommends a swizzling-based solution, which seems almost ridiculously over-the-top to me. Instead, I’ve gone with this nice simple snippet in a subclass:


© Mike Abdullah 2007-2015