0

I'm using xCode 4.3.2 and started a blank application.

I have a navigation controller and a simple logincontroller. I want the login controller to be my root view so it is this first thing that a user does when they login.

I'm using the following code and when I run the application it displays a black screen. I put in logging in the LoginViewController.m->ViewDidLoad and it is being run is there something im doing wrong the LoginViewController.xib is very simple it just contains a button right now that will switch to a tab view controller once I figure this out.

Thanks in advance.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:     (NSDictionary *)launchOptions
    {
        UIViewController *loginController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
        navigationController = [[UINavigationController alloc] initWithRootViewController:loginController];



        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [self.window addSubview:navigationController.view];
        [self.window makeKeyWindow];


        return YES;
    }
6
  • 1
    try self.window.rootViewController = navigationController instead of adding the nav controller's view as a subview in window. Commented Aug 28, 2012 at 17:36
  • @nielsbot I tried that still getting a black screen. I also tried self.window.rootViewController = loginController; and had the same problem. Does this mean the problem is in my LoginViewController??? Commented Aug 28, 2012 at 18:15
  • could be.. might want to make sure viewDidLoad and viewDidAppear are being called on your view controller, and check the frame of your view and whether its superview ≠ nil Commented Aug 28, 2012 at 19:06
  • Both viewDidAppear, and viewWillAppear are never hit... how do I check its superview ? Commented Aug 28, 2012 at 19:21
  • assert( view.superview ) but this won't be set until after viewDidAppear: is called. Note: It's -viewDidAppear:, not -viewDidAppear Commented Aug 28, 2012 at 19:23

1 Answer 1

1

This is not right:

[self.window addSubview:navigationController.view];

change it to this:

self.window.rootViewController = navigationController;
Sign up to request clarification or add additional context in comments.

2 Comments

Still only displays a blank screen.
Then comment out almost all the code and just do self.window.rootViewController = loginController;, and I'm going to guess that will be black too meaning something is wrong with that login controller - the nib name is misspelled, or nib is not included in project, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.