Warning :-Presenting view controllers on detached view controllers is discouraged

Gagan Joshi picture Gagan Joshi · Nov 10, 2013 · Viewed 136.7k times · Source

In my app, I am using a navigation controller. Later on in some view I am using presentViewController for showing a zoomed image. Also I am not using a Storyboard or nib.

I am getting this error in iOS 7 only. It works fine in iOS 6 and earlier:

Presenting view controllers on detached view controllers is discouraged

Answer

cdescours picture cdescours · Jan 8, 2014

To avoid getting the warning in a push navigation, you can directly use :

[self.view.window.rootViewController presentViewController:viewController animated:YES completion:nil];

And then in your modal view controller, when everything is finished, you can just call :

[self dismissViewControllerAnimated:YES completion:nil];