iPhone – 解雇RootViewController?

前端之家收集整理的这篇文章主要介绍了iPhone – 解雇RootViewController?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个RegistrationViewController和一个LoginViewController:

LoginViewController是我的InitialViewController / RootViewController.

如果我注册并单击Registrate-Button,它将自动推送到MainViewController.如果我按下logout-Button,它会关闭到RegistrationViewController,这是因为我使用[self dismissModalViewController animated:YES].

- (IBAction)logoutPressed:(id)sender {
  [self dismissModalViewControllerAnimated:YES];
   }

如果我按下logout-Button,我如何解除对LoginViewController的关注.

解决方法

您可以使用UINavigationController方法-popToRootViewControllerAnimated:.

- (IBAction)logoutPressed:(id)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

如果您正在谈论一个在另一个上面呈现的几个模态视图,您可以通过将-dismissViewControllerAnimated:completion:或者old -dismissModalViewControllerAnimated:发送到堆栈中的最低层来解除所有这些视图,如文档中所述:

If you present several view controllers in succession,thus building a stack of presented view controllers,calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens,only the top-most view is dismissed in an animated fashion

猜你在找的Xcode相关文章