Custom view in iPhone SDK gets placed incorrectly in realation to statusbar

Posted by markqvist on Stack Overflow See other posts from Stack Overflow or by markqvist
Published on 2010-04-04T00:49:17Z Indexed on 2010/04/04 0:53 UTC
Read the original article Hit count: 455

(ragh, i'm apparently not allowed to post images, so i have included links to the images in this post instead of embedding them)

Im writing an iPhone application based on the navigation controller template, but I am not loading the actual navigation controller as the first view in the window. I create a new view controller from a xib, and then add that as a subview, and then only push the navigation view as a modal when i need it. Here's my application: didFinishLaunching ... method in the application deleate

RootViewController *rootViewController = (RootViewController *)[navigationController topViewController];

rootViewController.managedObjectContext = self.managedObjectContext;

mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:[NSBundle mainBundle]]; mainViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[window addSubview:[mainViewController view]]; [[mainViewController view] setNeedsLayout];

[window makeKeyAndVisible];

return YES;

It works but the view is not properly aligned with the statusbar:

http://img.exdev.dk/1.png

When i click "my ambiances" and push the navigation controller view, and then dismiss it again, the layout is fine:

same link as above, just replace the 1 with a 2. Sorry for the hassle, apparently I can also only post one link....

Here's the code I use for presenting/dismissing the navigationcontroller:

-(void)pushMyAmbiences {
 [mainViewController presentModalViewController:navigationController animated:TRUE];
}

-(void)returnToMainView {
 [mainViewController dismissModalViewControllerAnimated:TRUE];
}

Is there anything I'm missing here? Layout-wise? Something that needs to be set in the xib? In a vain attempt I tried calling setNeedsLayout on the view, no luck. Any help is greatly appreciated!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uiviewcontroller