简体   繁体   中英

iOS Login with cancel and success on storyboard

This is my first iOS app and at this moment I'm struggling with Acccount / Login transitions on my storyboard.

What I'm trying to do is, If there is no logged user, display the login, otherwise display the account menu (Edit profile, My savings, and Logout). Actually I'm achieving with this code on my AccountMenuViewController:

- (void)viewDidLoad
{
    [super viewDidLoad];

    if (![self isLogged]) {
        [self presentLoginView];
    }    
}

#pragma mark - Login methods
- (BOOL)isLogged
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    return [[defaults objectForKey:@"loggedIn"] boolValue];
}

- (void)presentLoginView
{
    [self performSegueWithIdentifier:@"LoginSegueId" sender:self];
}

When the user touch "Cancel login" I'm trying to redirect to my MainView, I've make a segue but the Tab Bar is not displayed.

And when the login is ok, Close the login view.

I want to know your advices and tips, What are the best practices with this scenario?

This is my Storyboard.

MyStoryboard

First you should either make the login screen your rootViewController and just push to main view if

[self isLogged]==YES 

or have the Login presented in a model fashion with the main view as a root, that way instead of a segue you can just dismiss it and the main view will be present underneath. you can also have the main view push the login and just hide the nav bar and use 'cancel login' as a sort of '< back' button that you would see on the nav bar by using the popViewController method..... also you can simplify the method:

- (BOOL)isLogged
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    return [[defaults objectForKey:@"loggedIn"] boolValue];
}

can be :

- (BOOL)isLogged
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    return [[NSUserDefaults standardUserDefaults] boolForKey:@"loggedIn"];
}

hope i helped!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM