IOS: dismiss two viewController

泪湿孤枕 提交于 2019-12-06 02:02:55

问题


I have three viewController

First, Second and Third

from Second to open Third I use

Third *third = [[Third alloc]initWithNibName:@"Third" bundle:nil];
[self presentModalViewController:third animated:YES];
[third release];

Now I want return from third to first; then I set in viewDidAppear in second this code:

[self dismissModalViewControllerAnimated:NO];

but for 1 second I see Second and I don't want watch it...how can I do?


回答1:


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];
 }



回答2:


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];



回答3:


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



来源:https://stackoverflow.com/questions/10213321/ios-dismiss-two-viewcontroller

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