Search code examples
iosxcodeiphone-5viewdidloaddetailtextlabel

detailTextLabel.text not showing, on iPhone 5 only


I've solved this but it's worth sharing as I couldn't find anything on this.

I had a subclass of UITableView, with a detailTextLabel.text that was not displaying. The detailTextLabel object itself exists as normal, and contains the text, you just can't see it on the screen.

The bug only happens on the iPhone 5 or retina 4 inch simulator. It's fine on the iPod 4 or any other simulator "Hardware". The iOS version used makes no difference.

Answer is below.


Solution

  • Fixed it by having the view controller that triggered the display of the offending table do so in viewWillAppear instead of viewDidLoad.

    -(void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
    
        //Used to do this in viewDidLoad, but that stopped the detailTextLabel showing
        //for this table view on the iPhone 5. If do it from here, it's fine.
        [friendsSubView addSubview:friendsTableViewController.view];
    }