ios: how to dismiss a modal view controller and then pop a pushed view controller

僤鯓⒐⒋嵵緔 提交于 2019-12-04 18:32:31

问题


I have a view controller B that is pushed onto the navigation stack by root view controller A and this view controller B needs to display an alternative view if its model is in a certain state so it is modally presenting another view controller C. When I dismiss view controller C I would also like to pop view controller B if that is also on the nav stack. I would like to do it in such a way that there is only 1 transition.

Any ideas?


回答1:


In the scenario you posted, the presenting view controller for view controller C will actually be the navigation controller, so you can ask it to pop off B, and then dismiss yourself. This code is in view controller C:

-(IBAction)goBackToA:(id)sender {
    [(UINavigationController *)self.presentingViewController  popViewControllerAnimated:NO];
    [self dismissViewControllerAnimated:YES completion:nil];
}

If you are using a storyboard, you can do this same thing, jumping directly back to A with an unwind segue.



来源:https://stackoverflow.com/questions/16311305/ios-how-to-dismiss-a-modal-view-controller-and-then-pop-a-pushed-view-controlle

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