I've created a simple iPhone app which has two .xib files. In the app delegate at application did finish launching I display the first .xib file by calling:
[window addSubview:myView];
and I do the same on an IBAction for a UIButton to change the view to myView2.
What I'm finding is that there's a white bar of around 10 pixels when I run the app, for both views. I also notice that the buttons are offset by 10 pixels (approx.). So I get the impression that the view is being displayed from 10 pixels off the screen and ending short.
Any idea why this might be happening, how I can fix it, or how I can further debug what's going on? I've checked my .xib files and they are consuming the full height of the device (i.e. no white bars), so this looks to be a problem inside XCode.
EDIT: I've narrowed down the problem a little. I'm using two methods to load the subview. When I load the first view inside applicationDidFinishLaunching
everything is fine. However, if I replace the two messages to window
with the [self originalView]
method, then everything goes a bit haywire.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//[self originalView]; <- I want to use this instead of the following two lines
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
-(void)endView{
endV = [[EndViewController alloc] initWithNibName:@"EndView" bundle:nil];
[window removeFromSuperview];
[window addSubview:endV.view];
}
-(void)originalView{
viewController = [[MyAppViewController alloc] init];
[window removeFromSuperview];
[window addSubview:viewController.view];
}
From what I can see, I'm always calling the same lines of code, no matter if it's inside the applicationDidFinishLaunching
or in [self originalView]
but it seems like window
is turning out to be a different object.
Looks like you call pushVC to this
UIViewController
in the wrong place. I had the same problem. It was solved by moving[self.navigationController pushViewController: animated:]
fromviewDidLoad
toviewDidAppear:
in a previousUIViewController
in hierarchy.Whenever a weird gap appears, or the view is partly hidden behind the status bar, it has something to do with either
i had both bugs in my app and solved them! Hope I could save you some time (I wasted a lot on it)
In interface builder, you can add Simulated Interface Elements that will appear programatically (such as the status bar or the navigation bar). In your inspector, select your view, and go to the Attributes tab. Here you can simulate The Status bar, a top bar, or a bottom bar.
Here is my solution:
It works fine for me now, good luck~ :)
When using a UIViewController the normal way (i.e. pushing it on a UINavigationController), it adjusts its view's frame.
Since you're adding the subview manually, you have to adjust the frame yourself. The origin is in the upper right corner (at the top of the status bar). You want to shift your view 20 pixels down.