views:

212

answers:

1

I have several parts in my app where I use custom table view cells.

Their content is created with subviews.

The problem is that on some of these cells, the content does not appear at all or does not appear correctly until after the cell was selected for the first time.

One example is a custom cell which has a custom subview which can be set after its creation. This view does not appear at all before I selected the cell and its views were redrawn. Calling -[setNeedsDisplay] in the subview's setter method does not help either.

A: 

The problems was that I was using the cells themselves to calculate their height. For some reason, the subviews (which were part of the cell used to calculate the height) weren't appearing correctly in the cells that were used for the actual displaying.

Therefore my advice: Never use a UITableViewCell to calculate its own height. This may work in principle (it doesn't crash), but might bite you later in unexptected and hard-to-debug ways.

mrueg