I have created UITableViewController programatically in viewDidLoad():
resultsController = UITableViewController(style: UITableViewStyle.plain)
resultsController.tableView.register(MyTableCellTableViewCell.self, forCellReuseIdentifier: "userFoundCell")
resultsController.tableView.dataSource = self
resultsController.tableView.delegate = self
However, when I later do
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell: MyTableCellTableViewCell? = tableView.dequeueReusableCell(withIdentifier: "userFoundCell", for: indexPath) as? MyTableCellTableViewCell
if (cell == nil){
cell = MyTableCellTableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "userFoundCell")
}
cell!.lblTmp!.text = "test"
return cell!
}
cell is never nil, I have tested it
Code crash with:
fatal error: unexpectedly found nil while unwrapping an Optional value on cell!.lblTmp!.text = "test"
My MyTableCellTableViewCell looks like this
class MyTableCellTableViewCell: UITableViewCell {
@IBOutlet var lblTmp: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
IBoutlet is connected in Interface Builder to GUI elements. The same class is used on another place as well.
MyTableCellTableViewCelland how exactly are you connecting the label?resultsControlleris not instantiated from a storyboard.