0

I have a view controller that shows the details of an object. On this view controller is an "edit" button which shows modally the edition view controller. When I try to dismiss the modally presented view (edit view controller) :

self.dismissViewControllerAnimated(true, completion: nil)

I get the following error and it's presenting my initial viewController instead :

Warning: Attempt to present ≤Deevent.MyEventsVC: 0x7f99b70160a0≥ on ≤Deevent.EventCreationVC: 0x7f99b7238690≥ whose view is not in the window hierarchy!

So what I've tried was to set the root view controller of my view to the view I wanted to go back and present it in the completition of my dismiss. It's working well, but my application is in a Tabbar Controller and now it's not in it anymore. Same for the navigation controller.

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("MyEventsStoryboard") as! MyEventsVC

let appDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
appDelegate.window?.rootViewController = vc

self.dismissViewControllerAnimated(false, completion: {
                    self.presentViewController(vc, animated: true, completion: nil)
                })

Is there an other approach for presenting viewControllers after dismiss without leaving the Tabbar controller ?

Thanks

Nicolas Meienberger
  • 777
  • 2
  • 8
  • 18
  • what are u trying to acheive pls explain a little more – Ajay Beniwal Feb 12 '16 at 08:38
  • I have a view controller which shows the details of an object. On this view I have an "edit" button which shows the edition view controller modally. When I try to dismiss the edition view controller, I get the error and instead of showing me my details view controller, it shows me my initial (login) view controller. – Nicolas Meienberger Feb 12 '16 at 08:46
  • share the code where you are presenting view controller modally – Ajay Beniwal Feb 12 '16 at 08:50
  • It's just a performSegueWithIdentifier : `self.performSegueWithIdentifier("editEvent", sender: self)` – Nicolas Meienberger Feb 12 '16 at 08:53
  • For the error that you are getting, have you checked http://stackoverflow.com/questions/11862883/whose-view-is-not-in-the-window-hierarchy or http://stackoverflow.com/questions/28379327/ios-warning-attempt-to-present-viewcontroller-whose-view-is-not-in-the-window – Guy Daher Feb 12 '16 at 08:56
  • do you have navigation controller embedded inside your view – Ajay Beniwal Feb 12 '16 at 09:04
  • I just went through them and my main problem is not the same. I already tried those solutions, it works but as I said it shows me my vc without the tabbar and navigation controller. – Nicolas Meienberger Feb 12 '16 at 09:07
  • Did you first embed TabBarController -> Navigation Controller -> View Controller in your storyboard? Could you take a screenshot of your storyboard? – jo3birdtalk Feb 12 '16 at 09:51
  • It's a bit complicated. I have my details view which is embed in a navigation controller which is called by a view controller which is itself embed in a navigation controller which is embed in a tabbar controller. Maybe my problem is caused by the two navigation controllers. – Nicolas Meienberger Feb 12 '16 at 10:00

1 Answers1

-2

Since you are trying to present the new view controller by calling self.presentViewController after you dismiss self, you get the error. I can offer you a solution if you are using a navigation controller.

bcamur
  • 894
  • 5
  • 10