【发布时间】:2017-04-11 15:16:13
【问题描述】:
我想要一个名为 MainViewController 的可重用视图控制器,里面有一个 UITableView。
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
}
我需要我的 MainViewController 的许多子类,以便可以根据我的需要自定义它们。 IntroViewController 就是其中之一。
class IntroViewController: MainViewController {
}
要打开 IntroViewController,这里是我的转场:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "intro" {
let destination = segue.destination as! UINavigationController
let ivc = destination.topViewController as! IntroViewController
}
}
我遇到了这个崩溃:
fatal error: unexpectedly found nil while unwrapping an Optional value
换行
self.tableView.dataSource = self
我检查了,我的网点连接正确。数据源也是。
【问题讨论】:
-
什么是 StoryViewController ?
-
MainViewController,我更正了。
-
为什么在两个控制器之间导航控制器。?
-
你给表控制器的类名了吗?
-
我可以使用自定义 segue 而不是导航控制器
标签: ios swift uitableview uiviewcontroller subclass