ios - PushViewController 崩溃

标签 ios swift viewcontroller 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)

您对我做错了什么有任何指示吗?

这是我的 Storyboard的样子: enter image description here

堆栈跟踪: enter image description here

最佳答案

我的猜测是你的navigationControllernil。使用 ! 强制其解开将会导致崩溃。确保 navigationController 不是 nil

关于ios - PushViewController 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30844243/

相关文章:

ios - 如何从 UIPageViewController 内的 View Controller 返回上一个 VC 或下一个 VC?

ios - NSPredicate 对多关系

ios - 以编程方式循环 UIButton

ios - 如何从另一个访问某些变量的swift文件访问函数 - ios

ios - 使用 PanGestureRecognizer 裁剪 UIImageView 内 UIImage 的右侧

swift - any Identifiable 不能符合 'Identifiable'

ios - swift 2 在不同的 View Controller 中应用相同的背景

ios - 从 Assets 中选择它未显示在 SWIFT 的选项卡栏 Controller 中的图像

ios - 使用自动布局时如何使 UIScrollView 仅在一个方向上缩放

ios - EXC_BAD_INSTRUCTION - 从数组中获取随机项