Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Presenting view controllers on detached view controllers is discourage

Tags:

I'm using xcode 5.1.1 with storyboard. I have a button on main menu and it pops to another view controller with this code

VC *secondVC = [[VC alloc] init];
[self presentViewController:secondVC animated:YES completion: nil];

And there I have back button with this code

[self dismissViewControllerAnimated:YES completion: nil];

And when I pop to secondVC xcode gives me is error:

Presenting view controllers on detached view controllers is discourage <UINavigationController: 0x8c94510>.

I'm also having problem with rotation, it doesn't work properly.

like image 727
Alex Egorkin Avatar asked Aug 05 '14 17:08

Alex Egorkin


People also ask

How do you dismiss the presenting view controller?

When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it. In other words, whenever possible, the same view controller that presented the view controller should also take responsibility for dismissing it.

What does view controller do?

A view controller manages a single root view, which may itself contain any number of subviews. User interactions with that view hierarchy are handled by your view controller, which coordinates with other objects of your app as needed. Every app has at least one view controller whose content fills the main window.


2 Answers

This warning will come up if if you are trying to push, present or pop view controllers in viewWillAppear. I don't know what is in your code so it's tough to identify your problem but try using this if you are trying to show new views in viewWillAppear.

[self performSelector:@selector(yourMethod)
               withObject:nil afterDelay:0.0];
like image 171
Eric Alford Avatar answered Sep 18 '22 20:09

Eric Alford


Present the controller from viewDidAppear: instead.

like image 36
Aaron A. Avatar answered Sep 21 '22 20:09

Aaron A.