How to move to First viewController from last View controller among multiple view controllers

北城以北 提交于 2019-12-01 12:02:42

According to the doco for dismissModalViewControllerAnimated:

If you present several modal view controllers in succession, and thus build a stack of modal 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; any intermediate view controllers are simply removed from the stack.

So from your ContactUsViewController you need to call dismissViewControllerAnimated on the HomeViewController. You can access that view controller through parentViewController property. So your code in the dismissAction for the ContactUsViewController is:

- (IBAction)dismissAction:(id)sender
{
    // get your parent (ie AboutViewController)
    UIViewController * parent = self.parentViewController;

    // get its parent (ie HomeViewController)
    [parent.parentViewController dismissModalViewControllerAnimated:YES];
}

There might be a better way of getting to your HomeViewController, but for your shallow stack of view controllers, this should be fine (I tried this out and it worked).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!