I use two ViewControllers. A MainView and a FlipViewController. The MainView contains a bunch of buttons and controls, and a graphics display, and the FlipView contains the settings.
The MainView loads a different XIB depending on orientation to facilitate the variety of buttons I support and the graphics screen. This allows great flexibility to lay things out differently. The project was created initially before the StoryBoarding features were added to Xcode.
The normal usecase is I start in Portrait mode on the MainView, and then touch a button that rotates the FlipView into view. I do things on the FlipView (configure aspects of the program) and then commit the change, which rotates me back to the MainVIew. All is good so far.
The problem happens when I enter the FlipView and then rotate the device so the FlipView takes a different orientation. Lets say I rotate Portrait to Lanscape. Then return from the FlipView to the MainView. At this point, the MainView does not know about the Rotation that FlipView performed. So it is still showing the MainView in Portrait with the Portrait XIB.
The MainView's willRotateToInterfaceOrientation never gets called after returning from the FlipViewController. Thus it never finds out about the orientation change, and consequently, retains the incorrect XIB for that orientation. Here is a sample of the orientation handler in willRotateToInterfaceOrientation...
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// if portrait, load the portrait XIB for Pad or Phone
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[[NSBundle mainBundle] loadNibNamed:@"MainViewiPad" owner:self options:nil];
}else{
[[NSBundle mainBundle] loadNibNamed:@"MainView" owner:self options:nil];
}
[self viewDidLoad];
intorient = 1;
else.... handle Landscape...
So I have been experimenting with the viewWillAppear routine trying to find ways to cause the MainView to find out about the rotation and perform it in a system-wise manner. But so far I do not know how to cause the system to work in this manner. I suspect I will have to generate code that forces a reload of the correct orientation when viewWillAppear gets called. But this is not working correctly, because I never seem to get the change loaded in time, and it seems incorrect to try to reload a new XIB from within the viewWillAppear message.
Any help in understanding this behavior is much appreciated.