Reputation: 397
I have a couple of views all managed by their own controllers, some of them nested. I'd like to support rotation, some views are allowed to rotate to any orientation, some only to one of the portrait orientations (normal or upside down).
In my case, I need to implement -shouldAutorotateToInterfaceOrientation in my rootController to allow rotation for any of the subviews. The problem is, the rootController does not know if it should allow rotation because it needs to ask this to the subviews controller.
In my rootController's -shouldAutorotateToInterfaceOrientation I could do something like:
return [self.settingsController shouldAutorotateToInterfaceOrientation];
to provide the necessary logic of rotation but would this be the correct way to do this? I did read apple's doc about rotation, but this is not really adressed.
Upvotes: 1
Views: 756
Reputation: 3733
I found this post and the referenced blog the most concise guidance on doing nested view controllers. It's worth updating:
// "self" is the root view controller.
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
// The following is not available until iPhone 5.0:
[self presentViewController:self.subViewController animated:YES completion:NULL];
else
// For iOS 4.3 and earlier, use this (deprecated in 5.0):
[self presentModalViewController:self.subViewController animated:YES];
I've left it null here, but note that the new method allows you to send an inline function via the completion:
param. Per the class ref, it will be called after subViewController's viewDidAppear:
runs.
Upvotes: 0
Reputation: 397
For future reference I'll answer my own question.
My problem was that I had nested viewControllers and I displayed the view of a sub level viewController by calling something like:
self.view = _subLevelViewController.view;
or
[self.view addSubview:_subLevelViewController.view];
Apparently, nesting viewController like that is not what Apple intents for you to do.
You should stick with 1 "root viewController" and you should display other viewControllers using methods like:
[self presentModalViewController:_subLevelViewController animated:YES];
More info on the subject and a very good read:
http://blog.carbonfive.com/2011/03/09/abusing-uiviewcontrollers/
Upvotes: 1