xcode IOS:打开和关闭一些视图控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9031481/
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: open and close some view controllers
提问by cyclingIsBetter
In my app I have the following configuration to open my view controllers:
在我的应用程序中,我有以下配置来打开我的视图控制器:
When I write "pushViewController"I use a navigation controller, and when I write "present"I use a presentModalViewController
.
当我写“pushViewController”时我使用导航控制器,当我写“present”时我使用一个presentModalViewController
.
firtsView -> (pushviewcontroller) -> secondOneView -> (present) -> thirdOneView -> (present) -> fourthView
firstView -> (pushviewcontroller) -> secondTwoView -> (present) -> thirdTwoView
This is the scheme of my app to organize my view controllers. Then my question is:
这是我的应用程序组织视图控制器的方案。那么我的问题是:
What's the way to return from "fourthView"(that is when I go back from "fourthView") to "secondTwoView"?
从“fourthView”(即我从“fourthView”返回时)返回到“secondTwoView”的方法是什么?
Is there a way to do it?
有没有办法做到这一点?
回答by
Yes there are.
是的。
The UIViewController
offers different methods to dismiss a view controller depending on if you presented it modally or not. These are :
将UIViewController
取决于如果您呈现它有模式或不提供不同的方法来解雇一个视图控制器。这些是 :
-(void)dismissModalViewControllerAnimated:(BOOL)animated; // modal
-(void)dismissViewControllerAnimated:(BOOL)flag
completion:(void (^)(void))completion;
You will need to dismiss them one by one. Also, take time to read the View Programming Guidefrom Apple.
您将需要一一解雇它们。另外,花点时间阅读Apple的View Programming Guide。
Using a UINavigationController
you may pop to any view controller using :
使用 aUINavigationController
您可以使用以下命令弹出任何视图控制器:
-(NSArray *)popToViewController:(UIViewController *)viewController
animated:(BOOL)animated;
Alternatively, another method let you pop just one :
或者,另一种方法让您只弹出一个:
-(UIViewController *)popViewControllerAnimated:(BOOL)animated;
回答by IPaPa
if you use presentViewController
如果你使用presentViewController
i think you have to dismiss viewController one by one
我认为你必须一一关闭 viewController
but if you navigationcontroller only, then you can pop to viewController you want
但是如果你只使用导航控制器,那么你可以弹出你想要的视图控制器
回答by Zitao Xiong
- in thirdOneView's viewcontroller, do dismissModalViewControllerAnimated:NO
- in secondOneView's viewcontroller do dismissModalViewControllerAnimated:NO again.
- in secondOneView's viewcontroller do popViewControllerAnimated:NO
- in firstView's Viewcontroller do pushViewController to secondTwoView
- 在thirdOneView 的viewcontroller 中,执行dismissModalViewControllerAnimated:NO
- 在 secondOneView 的 viewcontroller 中再次 DismissModalViewControllerAnimated:NO。
- 在 secondOneView 的视图控制器中执行 popViewControllerAnimated:NO
- 在 firstView 的 Viewcontroller 中执行 pushViewController 到 secondTwoView
If you want some animation. I would suggest to do it manually by using CoreAnimation. Since
如果你想要一些动画。我建议使用 CoreAnimation 手动完成。自从
-(void)dismissViewControllerAnimated:(BOOL)flag
completion:(void (^)(void))completion;
is only available after iOS5.
仅在 iOS5 之后可用。