Hiding the Segue on Login process

after finding a good decision about not executing Segue thanks to the post

I ran into another problem: Following the approach described in the above post, I check my authentication token in the VC Dashboard and, if not installed, I activate segue pointing to LoginVC using the delegation mechanism to remove the view after the operation is completed . Now the problem is that on the very first launch, I got the Dashboard VC showing for a moment before LoginVC appears. I would like to show a login screen that immediately hides (in some way) the Dashboard VC. In other words, I want the user to not notice what is really happening.

Any idea? This is my current storyboard. enter image description here

DashboardVC :

- (void)viewWillAppear:(BOOL)animated {
//check if the token is set,if not trigger the Login screen
NSString* token = nil;
NSUserDefaults* userPref = [NSUserDefaults standardUserDefaults];
token = [userPref objectForKey:@"AuthToken"];
if (token == nil) {
    NSLog(@"Token not present,Login required!");
    [self performSegueWithIdentifier:@"sLogin" sender:nil];
    [super viewWillAppear:NO];

}
//[super viewWillAppear:YES];
}


// if the Segue was triggered by the "Logout" button we erase the token otherwise 
// simply perform the login since there was no token at all
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ([sender tag] == 5) {
    NSLog(@"User selected Logout");
    //remove the token
    NSUserDefaults* userPref = [NSUserDefaults standardUserDefaults];
    [userPref removeObjectForKey:@"AuthToken"];
    [userPref synchronize];
    NSLog(@"Token removed.");
}

if ([segue.identifier isEqualToString:@"sLogin"]) {
    LoginViewController *livc = segue.destinationViewController;
    livc.delegate = self; // For the delegate method
}

}

@ElJay, :)

!

+1
2

, , segue viewDidLoad , , .

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"LoggedIn"] == NO) {
        [self performSegueWithIdentifier:@"Push LogIn" sender:self];
    }

segue , , , rootviewController, , , , viewController login.

.h

@interface UIStoryboardSegueNoAnim : UIStoryboardSegue

@end

.m file

#import "UIStoryboardSegueNoAnim.h"

@implementation UIStoryboardSegueNoAnim

- (void)perform {
    [self.sourceViewController presentModalViewController:self.destinationViewController animated:NO];
}

@end
+1

, , segue, VC IB. segue VC Login VC .

, authToken ,

[self performSegueWithIdentifier:@"sDashboard" sender:self];

,

if (token == nil) {
    NSLog(@"Token not present,Login required!");
    [self performSegueWithIdentifier:@"sLogin" sender:nil];
    [super viewWillAppear:NO];

} else {
    [self performSegueWithIdentifier:@"sDashboard" sender:self];
}
+1

All Articles