简体   繁体   中英

Crash on pushViewController

I'm trying to push a ViewController, but my app crashes every time.

I'm using the UIImagePickerControllerDelegate to take a picture, and once the picture has been taken, this code runs:

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)
}

However, it always crashes on the last line:

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

XCode says: EXC_BREAKPOINT (code=1, subcode=0x100489474)

Do you have any pointers as to what I'm doing wrong?

Here's what my storyboard looks like: 在此处输入图片说明

The stack trace: 在此处输入图片说明

my advice try to push new view controller in dismissView compliation,

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

My guess is that your navigationController is nil . Forcing it to unwrap using ! will then result in a crash. Make sure that navigationController is not nil .

我知道问题已解决,但就我而言:将按钮从一个控制器情节提要板复制到另一个控制器,并将按钮插座与此一起复制到新的控制器并导致崩溃。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM