0

I know there are quite a few threads about that topic, and I tried every single option. But nothing works.

So, here what I have, a loginviewcontroller and a tabbarviewcontroller. If the device is already registered, the tabbar should appear, if not the loginview. I have the tabbarviewcontoller as initial view controller in storyboard. This works if the device is registered. This is what I basically do:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

//define viewcontroller
LoginViewController *loginviewcontroller = [[LoginViewController alloc]init];

//check if device id in coredata
NSString *deviceId = [self retrieveFromUserDefaults:cKey_DeviceId];
if(deviceId == nil){
    NSLog(@"device not registered");
    [self.window setRootViewController:loginviewcontroller];
    [self.window addSubview:loginviewcontroller.view];
}

//show them
[self.window makeKeyAndVisible];

return YES;

}

I have a NSlog output in my loginview viewdidload method, so I know, that the loginview is loaded. But the screen is black!!! I dont know why. The viewcontroller runs the viewdidload method, but there is just no screen output.

What do I do wrong???

thanks dominik

2 Answers2

0

If LoginViewController has a .xib file, you're calling the wrong init method. You want the initWithNibName:bundle: method.

Also, you do not need to call [self.window addSubview:loginviewcontroller.view]; after you set the root view controller.

And if the deviceId is NOT null, then you will get a blank screen.

And loginviewcontroller is leaking memory. You should release it after setting it to the root view controller.

picciano
  • 22,341
  • 9
  • 69
  • 82
  • Hi, I am working with stroyboard, so there is no .xib file just for loginviewcontroller. The weired thing is, that this is not the first app where I want similar thing. Last time with ios4 and without storyboard was it way easier. – Dominik Feininger Feb 10 '12 at 19:21
  • BTW: ios4.2 with sdk5 does not allow to release because of ARC, though. – Dominik Feininger Feb 10 '12 at 19:25
0

In most cases using a password, I've found it's best to load the initial (already logged in) screen, then check to see if a login is needed. If it is, immediately put up a login screen as a modal view. Launch the login screen from viewDidLoad in your initial screen.

Owen Hartnett
  • 5,925
  • 2
  • 19
  • 35
  • good idea, I will try it tomorrow, thanks. Sometimes when you are so "in" a problem you just don't see something else ;) – Dominik Feininger Feb 10 '12 at 23:36
  • which method would be the best to pop the modal view up? viewdidload or viewwillapear? or any other suggestons? – Dominik Feininger Feb 11 '12 at 09:12
  • The call you're looking for is presentModalViewController: animated: – Owen Hartnett Feb 12 '12 at 04:00
  • Hi, yeah sure. I ment the in which method should I call presentModalviewContoller, did it in viewdidload. And I thought it worked, but at the moment the loginview never pops up. @OwenHartnett – Dominik Feininger Feb 13 '12 at 09:58
  • if(!([deviceId length] > 0)){ NSLog(@"device not registered"); [self.tabBarController presentModalViewController:loginViewController animated:YES]; } and of course I get the output "device not registered" – Dominik Feininger Feb 13 '12 at 10:01
  • Don't call it from your tabBarController. Call it from your top most view or navigation controller, if you have one. – Owen Hartnett Feb 13 '12 at 13:03
  • Load your viewController for the first Tab item. Call your modal controller after that's loaded, when it's done it'll fall back to your first tab item. – Owen Hartnett Feb 13 '12 at 17:08
  • That is, load the first tab item's viewController when you start. Using that view, call [firstViewController presentModalViewController:loginViewController animated:YES] – Owen Hartnett Feb 13 '12 at 17:10
  • ok, made it. so much thx. solved it by sorted the loginview out of the storyboard and created a extra nib file for the loginview. – Dominik Feininger Feb 13 '12 at 19:48
  • It's considered good form to close off the question by indicating the answer. – Owen Hartnett Feb 14 '12 at 03:17