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

后端 未结 1 1994
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 13:03

Hii...i am new to iPhone programming..can anybody help me out please...!! I have multiple viewControllers..in First ViewController called HomeViewController i called the met

1条回答
  •  一整个雨季
    2021-01-16 13:28

    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).

    0 讨论(0)
提交回复
热议问题