开发者

White Screen using navigationController

开发者 https://www.devze.com 2023-04-04 18:07 出处:网络
I have to views which should be loaded depending on a return value. This is my code. After building the screen of the simulator stays white. Do you have suggestions what i should change. The logInView

I have to views which should be loaded depending on a return value. This is my code. After building the screen of the simulator stays white. Do you have suggestions what i should change. The logInView and createNewPasswordView are working. If I make them to the rootViewController of the window I can see them

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
PasswordHandling *aPasswortHandler = [[PasswordHandling alloc] init]; 
self.passwordHandling = aPasswortHandler; [aPasswortHandler release]; 
UINavigationController *navigationController;
if ([passwordHandling passwordInKeyChain] == TRUE) { 
    LogInView *logInView = [[[LogInView alloc] initWithNibName: @"LogInView" bundle: nil] autorelease]; 
    navigationController = [[UINavigationController alloc] initWithRootViewController:logInView];
} else { 
     CreateNewPasswordView *createNewPasswordView = [[CreateNewPasswordView alloc] initWithNibName:@"CreateNewPasswordView"开发者_如何学运维 bundle: nil]; 
     navigationController = [[UINavigationController alloc] initWithRootViewController:createNewPasswordView];

}

[self.window addSubview:navigationController.view]; 
[self.window makeKeyAndVisible]; return YES;

i noticed that the MainWindow.Xib is loaded. But that is not the xib file which should be loaded


Why are you programmatically creating your window in a project that has a nib file? Nib files are the correct solution to this kind of problem, and since you're using them anyway, there's no good reason to avoid the most basic one.

That said, the first thing you should do is replace this:

[self.window addSubview:navigationController.view]; 

With this:

[self.window setRootViewController:navigationController];

To debug your issues, you should check the frames of all the views you care about. I likely cause of this issue is that at least one of your frames is CGRectZero.

** EDIT **

It's not a problem that the VCs have their own nib files. The problem is that you should be using the window created by MainWindow.xib. Especially if you're new, there is no reason you should be creating your window in code. Remove your creation of the window, make sure that self.window is not nil at the point you're running this code, and use setRootViewController rather than addSubview.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号