Im really struggling with this basic programming stuff but I just can’f figure out whats happening and how to solve it.

I have my main Login controller that detects when a user is logged in and presents next controller if auth succeed:

@interface LoginViewController (){

    //Main root instance
    RootViewController *mainPlatformRootControler;

-(void)loggedInActionWithToken:(NSString *)token anonymous:(BOOL)isAnon{
    NSLog(@"User loged in.");

    mainPlatformRootControler = [self.storyboard instantiateViewControllerWithIdentifier:@"rootViewCOntrollerStoryIdentifier"];

    [self presentViewController:mainPlatformRootControler animated:YES completion:^{



And that works well, no problem.

My trobule is handling logout. How do I delete completely the RootViewController instance and show a new one?

I can see that RootViewController instances are stacking cause I have multiple observers and after a logout and then login they are called multiple times (as many times I exit and re-enter).

I’ve tried the following with no success:

First detecting logout in RootViewController and dismissing:

[self dismissViewControllerAnimated:YES completion:^{
                [[NSNotificationCenter defaultCenter] postNotificationName:@"shouldLogOut" object:nil];


And then in LoginViewController:

-(void)shouldLogOut:(NSNotification *) not{
    NSLog(@"No user signed in");
    mainPlatformRootControler = NULL;
    mainPlatformRootControler = nil;

So how can I handle this? I know its a basic handle stuff but I just dont know how??? Thanks.

Source link


Please enter your comment!
Please enter your name here