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
Lots of reasons for this warning. Mine is because I have a segue connected from a ViewController to another that will be presented modally. But, the ViewController I am presenting from is being dynamically generated by a PageViewController. Which is why it is detached in the Storyboard. My app isn't going to crash because of it; but I would like to silence the warning.
Wait for
viewDidAppear()
:This error can also arise if you are trying to present view controller before view actually did appear, for example presenting view in
viewWillAppear()
or earlier. Try to present another view afterviewDidAppear()
or inside of it.you need to add the view controller that will present the new controller as a child of the parent view controller.
Let's say you have yourMainViewController, then you add a new controller called controllerA, and then you want to present a new controller called controllerB from controllerA
you have to write something like this:
and within controllerA you can present the new controller without warnings
To avoid getting the warning in a push navigation, you can directly use :
And then in your modal view controller, when everything is finished, you can just call :
[self dismissViewControllerAnimated:YES completion:nil];
Swift 3
For anyone stumbling on this, here is the swift answer.
Make sure you have a root view controller to start with. You can set it in
didFinishLaunchingWithOptions
.