UITableViewCell, auto layout, and accessoryType

I just burned a few hours on this:

Auto layout for UITableView cells is awesome. It’s so much easier than what we had before which was having to measure cells before they existed.

With auto layout, as long as you specify the height of the cell’s contents in relation to its superview (by having constraints connecting vertically from the top edge, through all the cells, to the bottom edge), UITableView figures out the height by solving the constraints.

The catch is that if you add an accessory, like the UITableViewCellAccessoryDisclosureIndicator, this breaks. It seems to work okay in Interface Builder, but at runtime, the height of, for example, a UILabel that is supposed to wrap text, will not wrap it correctly.

It’s easy enough to reproduce, in my case at least.  Create a new project, add a table view, add a cell whose content is a label, constrain it to the edges of the cell, and then at runtime, set enough text that it needs to wrap.  With no accessory view, the label wraps fine. Add the accessory, and it stops wrapping.

Radar logged.