Reputation: 95
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.
Upvotes: 0
Views: 357
Reputation: 2809
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.
Upvotes: 0
Reputation: 5935
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.
Upvotes: 1