pushViewController 崩溃

Crash on pushViewController

我正在尝试推送 ViewController,但我的应用程序每次都崩溃。

我正在使用 UIImagePickerControllerDelegate 拍照,拍照后,此代码运行:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
    let pickedImage = info[UIImagePickerControllerEditedImage] as! UIImage

    // Reset the cameraButton and Tabbar
    self.cameraButton.setImage(UIImage(named: "camera-button"), forState: .Normal)
    self.cameraButton.transform = CGAffineTransformMakeScale(1, 1)
    self.tabBarController?.tabBar.alpha = 1

    let realmImage = Image()
    realmImage.imagedata = UIImageJPEGRepresentation(pickedImage, 1.0)

    let birthmark = Birthmark()
    //birthmark.imagesArray = RLMArray()
    birthmark.imagesArray.addObject(realmImage)
    birthmark.bodyPart = Birthmark.Bodypart.LeftArm

    realm.beginWriteTransaction()
    realm.addObject(birthmark)
    realm.commitWriteTransaction()

    self.dismissViewControllerAnimated(true, completion: nil)

    let secondViewController = self.storyboard!.instantiateViewControllerWithIdentifier("ItemViewController") as! ItemViewController
    secondViewController.existingItem = birthmark
    navigationController!.presentViewController(secondViewController, animated: true, completion: nil)
}

然而,它总是在最后一行崩溃:

navigationController!.presentViewController(secondViewController, animated: true, completion: nil)

XCode 说:EXC_BREAKPOINT(代码=1,子代码=0x100489474)

你对我做错了什么有什么建议吗?

这是我的故事板的样子:

堆栈跟踪:

我的建议是尝试在 dismissView compliation 中推送新的视图控制器,

self.dismissViewControllerAnimated(true, completion: {
     let secondViewController = self.storyboard!.instantiateViewControllerWithIdentifier("ItemViewController") as! ItemViewController
     secondViewController.existingItem = birthmark
     navigationController!.presentViewController(secondViewController, animated: true, completion: nil)
});

我猜你的 navigationControllernil。使用 ! 强制它解包将导致崩溃。确保 navigationController 不是 nil.

我知道问题已解决,但在我的情况下:我将一个按钮从一个控制器故事板复制到另一个,按钮插座也随之复制到新控制器并导致崩溃。