2015-06-15 6 views
0

Я пытаюсь нажать ViewController, но мое приложение падает каждый раз.Crash on pushViewController

Я использую 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)

Есть ли у вас какие-либо указания относительно того, что я делаю неправильно?

Вот что моя раскадровки выглядит следующим образом: enter image description here

Трассировка стека: enter image description here

+0

Можете ли вы предоставить трассировку стека? –

+0

Почему вы просите навигационный контроллер представить второй контроллер. Почему бы не использовать 'self.presentViewController'? –

+0

Исключено исключение. Возобновите выполнение программы и дайте ей сбой, чтобы сообщение об ошибке было распечатано на консоль. – Sulthan

ответ

0

Я думаю, что ваш navigationController является nil. Принудительное развертывание с использованием ! приведет к сбою. Убедитесь, что navigationController не nil.

+0

Да, это то, что я тоже думаю. Я просто не понимаю, как navigationController может быть nil –

+0

@ PæturMagnussen В каком контроллере вы находитесь? Мы не можем видеть контекст метода. – Sulthan

+0

Вы были правы. Я не был на самом деле в navigationController, поэтому он был нулевым. –

0

мой совет попытаться подтолкнуть новый контроллер представления в dismissView compliation,

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

Я думаю, он должен вызвать picker.dismissViewControllerAnimated – agy

+0

Он все еще сбой :( –