I would like to have a reusable view controller called MainViewController with a UITableView inside.
class MainViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var tableView : UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.dataSource = self
self.tableView.delegate = self
self.tableView.scrollsToTop = true
self.tableView.estimatedRowHeight = 124.0
self.tableView.rowHeight = UITableViewAutomaticDimension
}
I need to have many subclasses of my MainViewController, to can custom them depending of my needs. IntroViewController is one of them.
class IntroViewController: MainViewController {
}
To open the IntroViewController, here my segue:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "intro" {
let destination = segue.destination as! UINavigationController
let ivc = destination.topViewController as! IntroViewController
}
}
I got this crash:
fatal error: unexpectedly found nil while unwrapping an Optional value
for the line
self.tableView.dataSource = self
I checked, my outlets are linked correctly. Datasource too.