I am using more than one table view cell class on a table view. I have registered the reuse identifiers and the xibs. For some reason the cells are not showing. What should I check. I'm stumped.
Here is my code:
import UIKit
class DetailTableViewController: UITableViewController {
let items = [0, 1]
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(DueDateSwitchTableViewCell.self, forCellReuseIdentifier: "DueDateSwitchTableViewCell")
let xibDueDateSwitchTableViewCell = UINib(nibName: "DueDateSwitchTableViewCell", bundle: Bundle.main)
tableView.register(xibDueDateSwitchTableViewCell, forCellReuseIdentifier: "DueDateSwitchTableViewCell")
tableView.register(DueDatePickerTableViewCell.self, forCellReuseIdentifier: "DueDatePickerTableViewCell")
let xibDueDatePickerTableViewCell = UINib(nibName: "DueDatePickerTableViewCell", bundle: Bundle.main)
tableView.register(xibDueDatePickerTableViewCell, forCellReuseIdentifier: "DueDatePickerTableViewCell")
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print("tableView(_:cellForRowAt:)", "indexPath.row=", indexPath.row)
let cell = UITableViewCell()
switch indexPath.row {
case 0:
print("\tcase 0")
let cell = tableView.dequeueReusableCell(withIdentifier: "DueDateSwitchTableViewCell", for: indexPath) as! DueDateSwitchTableViewCell
cell.backgroundColor = UIColor.yellow
case 1:
print("\tcase 1")
let cell = tableView.dequeueReusableCell(withIdentifier: "DueDatePickerTableViewCell", for: indexPath) as! DueDatePickerTableViewCell
cell.datePicker.date = Date()
default:
break
}
return cell
}
}
The cells show the numbers when I use this code in tableView(_:cellForRowAt:) before the line that says "return cell":
cell.textLabel!.text = String(items[indexPath.section].hashValue)