Reputation: 37
I'm trying to do the following:
UIImagePickerController
pops upUIImagePickerController
is dismissedAs of now, I have it set up that when the user presses a button, a UIImagePickerController is initialized and presented with presentViewController. It is also delegated to the class that this button is linked to as well. After the user picks an image, imagePickerController is called, and dismissViewControllerAnimated
is also called. Then, performSegueWithIdentifier
is called. However, this last step throws the following warning, and then does not segue:
2016-09-15 03:45:44.870 Food Diary[9941:1540144] Warning: Attempt to present on whose view is not in the window hierarchy!
I am very new to Swift and iOS development, what does this mean and how do I fix it?
Upvotes: 1
Views: 1387
Reputation: 4632
It stays on the same ViewController because the UIImagePickerController
is still in view hierarchy a the d second ViewController cannot be added on top of UIImagePickerController
. To fix, you need to wrap your segue in the completion of UIImagePickerCopntroller
dismissal like this:
self.dismiss(animated: true, completion: {
self.performSegue(withIdentifier: "StartToMain", sender: nil)
})
Upvotes: 0
Reputation: 1610
Try to using these two lines code during presenting and dissmising your view controller
Presenting :
self.view.window.rootviewcontroller.presentViewController("yourVC",animated:true, nil)
Dissmising :
self.view.window.rootViewController.dismissViewController(animated:true completion:nil)
Upvotes: 0
Reputation: 72410
Perform segue on completion of dismiss of UIImagePickerController
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
// your code
self.dismissViewControllerAnimated(true, completion: {
self.performSegueWithIdentifier("SegueIdentifier", sender: self)
})
}
Note: With sender I have passed current Controller object you can any object that you want.
Upvotes: 5