In my application, i have a navigation controller
. I have added a back button to go to the login screen (UIViewController)
. How do i go back to the login screen from the navigation controller
?
This is the code for my back button.
(void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonSystemItemCancel target:self action:@selector(goBacktoLogin)];
self.navigationItem.leftBarButtonItem = backButton;
}
(void) goBacktoLogin
{
LoginViewController *loginViewController = [[ LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
[[ self navigationController] popToViewController:loginViewController animated:YES];
}
I am getting the following error:
* Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Tried to pop to a view controller that doesn't exist.'