Is it correct to present a conditional login screen when starting the application using the storyboard and controllers with separate viewing?

It seems like it should be simple, but it has a lot of complex nuances - and I did not find an answer elsewhere on Stack Overflow that answers this completely, clearly, and simply.

In a nutshell: I have an iPad app that uses storyboards to compose an application stream and a split view controller as the primary root view controller.

This application checks at startup if login credentials are stored, and if they jump directly to the user interface, and if not, it presents a full-screen login page.

The problem though is - where should this conditional check be performed and how should the login screen be instantiated?

I tried every permutation that I can think of.

In the application, the delegate seems like an obvious place, but the call to segues or modal pop-ups seems to be ignored, because the views from the storyboard do not yet live.

In the launch methods for a part controller with a split view, visibility appears to be the next obvious place.

The closest to working solution that I can find is described here: https://stackoverflow.com/a/416829/

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"Login"];
    [vc setModalPresentationStyle:UIModalPresentationFullScreen];

    [self presentModalViewController:vc animated:NO];
}

But with this implementation, called up by the split view view controller, a brief view of the screen is displayed briefly on the screen.

viewDidAppear viewWillAppear, , , .

, , , , , , .

- ? ?

+4
4

, . , , :

-(void)viewWillAppear:(BOOL)animated {

    // Check if user is already logged in
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    if ([[prefs objectForKey:@"log"] intValue] == 1) {
        self.view.hidden = YES;
    }
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    // Check if user is already logged in
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    if ([[prefs objectForKey:@"log"] intValue] == 1) {
        [self performSegueWithIdentifier:@"homeSeg3" sender:self];
    }
}

-(void)viewDidUnload {
    self.view.hidden = NO;
}
+2

window.hidden NO, subviews:

UITabBarController* tc = (UITabBarController*) self.window.rootViewController;

// Present the log in view controller
self.window.hidden = NO; // the window is initially hidden
[tc presentViewController:logInViewController animated:NO completion:NULL];
+1

SWIFT

override func viewWillAppear(animated: Bool) {
    let prefs:NSUserDefaults = NSUserDefaults.standardUserDefaults()

    let isloggedIn = prefs.objectForKey("isLoggedIn") as? Bool
    if (isloggedIn != false) {
        self.view.hidden = true
    } else {
        self.view.hidden = false
    }
}

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(true)

    let prefs:NSUserDefaults = NSUserDefaults.standardUserDefaults()

    let isloggedIn = prefs.objectForKey("isLoggedIn") as? Bool
    if (isloggedIn != false) {
        println("this should work")
        self.performSegueWithIdentifier("Login", sender: self)
    }
}
0

, , , . , .

, , segue... / .

-1

All Articles