【发布时间】:2019-01-15 00:40:11
【问题描述】:
我知道标题有点奇怪,但我尝试将 UITableViewController 替换为 UIViewController 并使用以下代码:
@objc func buttonAction(sender: UIButton!) {
let newController = JobTableViewController()
self.navigationController?.present(newController, animated: true, completion: nil)
}
但每次我点击此按钮时,我的ViewController 在此代码行中都会出现以下错误
tableView.delegate = self
线程 1:致命错误:打开包装时意外发现 nil 可选值
【问题讨论】:
-
如果您使用故事板,那么您需要在
storyboard中连接tableView。如果以编程方式,则需要在访问之前对其进行初始化。 -
tableView.delegate = self写在viewController的什么地方? -
@Abizern 在 ViewDidLoad 中,但我现在可以正常工作了,所以没关系,谢谢 :)
标签: ios swift uitableview uiviewcontroller delegates