Question

I have a self-made "log out controller" for my app, and I would appreciate your help on a problem.

My "log out controller" is included my app, accessed by a simple side swipe from another controller; however, I've placed the "log out" button in a simple UITableViewController.

My problem occurs when I hit the "log out" button, the app crashes, and I'm unsure of quite how to parse the data so that the user is successfully logged out once they hit the button. If anybody could tell me where I'm going wrong it would be lifesaving!

- (IBAction)logOutAction:(id)sender {

    NSLog(@"yes");

    PDKeychainBindings *bindings = [PDKeychainBindings sharedKeychainBindings];
    [bindings setObject:@"no" forKey:@"loggedIn"];
    [bindings setObject:@"" forKey:@"userID"];

    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    UINavigationController *nav = (UINavigationController*)window.rootViewController;
    UIViewController *login = [nav.viewControllers  objectAtIndex:0];
    UINavigationController *slider = (UINavigationController*)login.presentedViewController;

    self.logOutButton.enabled = NO;
    [self.logOutButton setAlpha:0.8];

    [self performSelector:@selector(logOutAction:) withObject:nil afterDelay:0.1];
    [self setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [login dismissViewControllerAnimated:YES completion:^{ 

    }];
}


- (IBAction)close:(id)sender {

    //UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    //DYNavigationController *nav = (DYNavigationController*)window.rootViewController;
    //UIViewController *login = [nav.viewControllerStack objectAtIndex:0];
    // CustomNavController *slider = (CustomNavController*)login.presentedViewController;
    //[self setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    //[login dismissViewControllerAnimated:YES completion:^{    
    // }];

    [self dismissViewControllerAnimated:YES completion:nil];
}
Was it helpful?

Solution

You haven't given exception details, but it looks like you are calling the instance after is has been deallocated.

In the logOutAction: method you are setting up a future call using [self performSelector:@selector(logOutAction:) withObject:nil afterDelay:0.1];. Then you are dismissing the view. So when logOutAction: is called in 0.1 seconds the instance wont exist and you will crash.

It makes no sense to use performSelector here - remove it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top