xcode IOS:关闭两个viewController
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10213321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IOS: dismiss two viewController
提问by cyclingIsBetter
I have three viewController
我有三个 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:
现在我想从第三回到第一;然后我在第二个代码中在 viewDidAppear 中设置:
[self dismissModalViewControllerAnimated:NO];
but for 1 second I see Second and I don't want watch it...how can I do?
但是有 1 秒钟我看到了 Second 并且我不想看它……我该怎么办?
回答by rakeshNS
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];
}
回答by GoZoner
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];
回答by Ankit Srivastava
This happens coz viewDidAppear is called everytime before the view appears so as soon as it appears you dismiss it and it disappears..
发生这种情况是因为 viewDidAppear 每次在视图出现之前都会被调用,所以只要它出现,你就会关闭它并消失。
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
我不认为你想要做的事情可以用 modalViewControllers 来实现......而是使用 navigationController 并继续将你的视图控制器添加到堆栈中,当你想转到第一个视图控制器时,只需调用
[self.navigationController popToRootViewControllerAnimated:YES];
EDIT
:
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.)
只是想到这可以通过使用委托来实现..你让第二个代表第三个,一旦你解除第三个控制器向代表发送一个消息。在这个消息调用中[self dismissModalViewControllerAnimated:NO];
..你就完成了..(如果你很容易知道委托。)