我正在开发的应用程序包含 Map 视图,一切正常 . 我可以与 Map 等进行互动 .

但是,当我点击我放置在 Map 视图下的按钮以仅使用一些标签和开关执行到设置视图中的segue时,我得到Swift的可选解包错误:

fatal error: unexpectedly found nil while unwrapping an Optional value

错误发生在我为初始视图创建的 Map 视图上,当我检查调试控制台时, Map 视图似乎为nil,因为错误消息相关 .

为什么segue关心 Map 视图被解除分配并引发异常?我该如何解决这个问题?

My Code & Storyboard:

override func viewDidLoad() {
    super.viewDidLoad()

    locationManager = CLLocationManager()
    locationManager.requestWhenInUseAuthorization()
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.startUpdatingLocation()

    self.configureFloorPlan()
}

func configureFloorPlan() {
    ...
    // the crash happens at the following line of code when I press the button
    mapView.addOverlay(HideBackgroundOverlay.hideBackgroundOverlay(), level: .AboveRoads)
    ...
}

当我按下初始视图控制器左下角的信息按钮时,会启动segue .

enter image description here

当我删除目标视图控制器的类时,崩溃将解决 . 这很有趣,因为目前这个课程是空的 .