Hello,
I’m at a loss as to why this function in LocationDetailsController works in the final sample code but fails for me (I added the “print” statements in my version, as well as the checks for nil in the label text):
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.backgroundColor = UIColor.black
print("\(indexPath)")
if let textLabel = cell.textLabel {
if let text = textLabel.text {
print("textLabel.text is \(text)")
}
textLabel.textColor = UIColor.white
textLabel.highlightedTextColor = textLabel.textColor
}
if let detailLabel = cell.detailTextLabel {
detailLabel.textColor = UIColor(white: 1.0, alpha: 0.4)
detailLabel.highlightedTextColor = detailLabel.textColor
}
let selectionView = UIView(frame: CGRect.zero)
selectionView.backgroundColor = UIColor(white: 1.0, alpha: 0.2)
cell.selectedBackgroundView = selectionView
}
In my code, both cell.detailTextLabel.text and cell.textLabel.text are nil in every row in the table at runtime. That makes sense to me since we hooked up all those labels that change to IBOutlet instance variables up at the top of the class, and set those instance variables to the appropriate values. Likewise the textLabel equivalents are labels that we dragged onto the storyboard, rather than setting them programmatically in viewDidLoad or somewhere.
In the equivalent place in the sample code I added print statements and see “Category”, “Description”, etc printed out in the debug area as the cells are displayed, so clearly the sample code knows that the configured static values correspond to UITableViewCell’s built-in labels
I compared every settable property I could find in main.storyboard for these UILabels with my project and the final project, and I can find no difference. Likewise with the code. Is there some magic that happens somewhere I’m missing to tell the storyboard that our instance variable labels/static labels correspond to the built-in UITableViewCell “textLabel”?