在我的应用程序中,我有一个导航 Controller
。我添加了一个后退按钮以转到登录屏幕(UIViewController)
。如何从导航 Controller
返回登录屏幕?
这是我的后退按钮的代码。
(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];
}
我收到以下错误:
* Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Tried to pop to a view controller that doesn't exist.'
最佳答案
如果您需要返回导航层次结构中的第一个 View Controller ,请使用:
[self.navigationController popToRootViewControllerAnimated:YES];
关于ios - 导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11290480/