IOS: dismiss two viewController

廉价感情. 提交于 2019-12-04 05:25:00

You need to dismiss third view controller first and then second Viewcontroller. Do the following code when you want to go first view controller.

-(void)goToFirstView{
        UIViewController *vc = [self parentViewController];
   //     UIViewController *vc = [self presentingViewController]; //ios 5 or later
        [self dismissModalViewControllerAnimated:NO];
        [vc dismissModalViewControllerAnimated:YES];
 }

How is the Third modal view being dismissed in the first place? Perhaps by the user touching a 'Done' button? If so, it is in the handler for the button that you want to dismiss both.

You can dismiss both as:

[self dismissModalViewControllerAnimated: YES];
[self.presentingViewController dismissModalViewControllerAnimated: NO];

This happens coz viewDidAppear is called everytime before the view appears so as soon as it appears you dismiss it and it disappears..

I don't think what u are trying to do can be achieved with modalViewControllers... instead use a navigationController and keep adding your viewcontrollers onto the stack and when you want to goto the First view controller just call

 [self.navigationController popToRootViewControllerAnimated:YES];    

EDIT:

just thought of it this can be achieved by using delegation.. you make second the delegate of third and as soon you dismiss the thirdviecontroller send the delegate a message.In this message call [self dismissModalViewControllerAnimated:NO];.. and you are done.. (pretty easy if you know delegation.)

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