My app consists of 3 views. I’ve defined 3 helper methods in the AppDelegate to switch between each view (so that each view can call the other), which look like this:
-(IBAction)goToView1 {
if ( view1 == nil )
{
View1 *thisView = [[View1 alloc] initWithNibName:@"View1" bundle:nil];
view1 = thisView;
}
for (UIView *view in window.subviews)
[view removeFromSuperview];
[window addSubview:view1.view];
}
If the user wants to switch to another view, I tie a button to an IBAction defined in the view’s controller:
-(IBAction)goToOtherView:(id)sender {
ViewSwitcherAppDelegate *root = [[UIApplication sharedApplication] delegate];
[root goToView1];
}
This all works fine for switching views, but when the view is drawn it is displays incorrectly, like it is ignoring the status bar:
alt text http://lh4.ggpht.com/_nbwj7pSrW10/SkcGEZ3XH0I/AAAAAAAABMs/nAkkja27e8I/s576/ViewSwitchingProblem.png
What am I doing wrong?
It renders fine when the app starts up, so I suspect there’s something wrong in the way I am adding the subview to the window.
Thanks in advance!
Since you’re not using the view’s controller to display it, you have to adjust the view’s frame yourself. You have to set its origin to {0, 20} to take the space for the status bar into account.
But you’d be better off to use the UIViewController and push this on the UINavigationController. See the docs.