【发布时间】:2019-05-26 13:57:49
【问题描述】:
我正在尝试以编程方式显示我的 ViewControllers 中的一个不同的故事板。但由于某些原因,我试图展示的ViewController 的属性为零。
这是我的错误:Unexpectedly found nil while unwrapping an Optional value
我在
SecondViewController中收到错误消息。它显示但 由于属性为零,我的应用程序崩溃了。
这是我的代码:
let secondStoryBoard = UIStoryboard(name: "SecondStoryBoard", bundle: nil)
let secondViewController = secondStoryBoard.instantiateViewController(withIdentifier: "secondVC") as! SecondVC
self.navigationController?.pushViewController(secondViewController, animated: true)
这是产生错误的代码:
class SecondVC: ViewController
{
@IBOutlet weak var mapView: MKMapView!
mapView.isHidden = true // ERROR!! Unexpectedly found nil while unwrapping an Optional value
}
已解决:只需重新连接我的
@IBOutlet连接
【问题讨论】:
-
我知道这意味着什么。我只是不知道为什么会出现此错误
标签: swift uiviewcontroller uinavigationcontroller uistoryboard uistoryboardsegue