Thread 1: signal SIGABRT on button clicked

360 views Asked by At

I am implementing a logout button in my project. I attached it by using the touch up inside event. When logout clicked, the user is redirected to login view controller but for some strange reason the application dies after a few seconds with the following error. Thread 1: signal SIGABRT.

Logout clicked: (all this method does is erasing the username and redirecting to "Login" view controller)

-(IBAction)logout {

[[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"User"];

[self dismissViewControllerAnimated:NO completion:nil];

UIViewController * vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Login"];
[self presentViewController:vc animated:NO completion:nil];

}

Login page has nothing when it loads.

2

There are 2 answers

0
Owen Hartnett On BEST ANSWER

Your signature for logout is all wrong. You should change the message line to:

-(IBAction) logout:(id) sender {

You can ignore sender if you like. Your touch up inside is expecting to send a message to a method which has a parameter, and yours doesn't. That's why you're crashing.

1
Lolloz89 On

Try changing your code with this:

-(IBAction)logout {

    [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"User"];

    [self dismissViewControllerAnimated:NO completion:^{
        UIViewController * vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Login"];
        [self presentViewController:vc animated:NO completion:nil];
    }];

}

Probably you are showing the new viewController before the old one has been dismissed, even if you do that not animated.