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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…