UITableView cells appear on top of each other?

Heres an easy mistake to make that produces some unexpected results.  I had an issue where it appeared like I had UITableView cells appearing on top of each other.  Looking like this :

I must have set up 100s of UITableViews over the years.  Well – 9 years now doing iOS.  My first thought was that this was in fact cells not being reused properly – something not set up with reuse identifiers, or something along those lines.  So I checked my custom cells, setup in the storyboard – all ok.

Then I checked the Debug View Hierarchy to have a closer look at what was going on.  It looked like this :

So theres an extra label on top of the label I placed in my cell, which is referred to as Class Name : UITableViewLabel.  I didnt even know such thing exists.  Then it occurred to me ….. and heres what I was doing wrong.  In my cell configuration method, Im not setting the label I placed in my custom cell.  Im setting the label that occurs in the standard UITableViewCell.  ie, Im doing :

Instead of setting my own custom cells label :

The obvious clue is in the colouring from my XCode colour scheme – standard UIKit stuff is in pale blue, while my custom properties are in green. Setting this standard UITableViewCell label having created already created a custom cell, results in this UITableViewLabel being created and added to the top of the custom view – hence the weird stacked appearance. Hope this is of help to someone in future!

Leave a Reply

Your email address will not be published. Required fields are marked *