In my swift project I have a tableViewController, with class TableViewController, and one prototype cell, with class TableViewCell. Now I want to use: tableView.reloadData(), or other function, in the class TableViewCell. I put a button into the prototype cell, here the code:
class TableViewCell: UITableViewCell {
let tableViewController = TableViewController()
@IBAction func actionButton(_ sender: UIButton) {
tableViewController.tableView.reloadData() // or other function
}
}
by this method the result is: unexpectedly found nil while unwrapping an optional value. I checked that the class TableViewController is loaded before than the class TableViewCell, so I don't found the problem. Can you help me to find how this error occur?
you can't call TableViewController from other class
you need to use NotificationCenter or protocol