我正在尝试推送 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的样子:
堆栈跟踪:
最佳答案
我的猜测是你的navigationController
是nil
。使用 !
强制其解开将会导致崩溃。确保 navigationController
不是 nil
。
关于ios - PushViewController 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30844243/