UIViewControllers - View1, View2, View3 displayed in succession

别等时光非礼了梦想. 提交于 2019-12-11 15:12:05

问题


I have three UIViewControllers that I need to show in succession. The UIViewController1 is my main view controller and has a button. Clicking on the button displays UIViewController2 modally. After 30 seconds, UIViewController3 is automatially shown modally. Do I have to first dimiss UIViewcontroller2 and then display UIViewController3?. I have a Done button on UIViewcontroller3 and clicking on it should take me back to UIViewController1 (main view controller). Do I have first dismiss UIViewController2 from the chain and then do a alloc/init on UIViewController1 to show it?. I don't want to get any memory leaks in this process.

Please help.


回答1:


There are two main ways that you can do this, one of which, you have alluded to. After testing this scenario in XCode.

The first involves dismissing all modal view controllers from the final view controller (the third). By doing this, you cannot use animation to dismiss the view controllers. If you try to animate them, the second will not be dismissed. (Granted, you could dismiss the second one with animation, but it would display the animation from the second to the first, rather than from the third to the first)

To do this, you'll need to pass your second view controller as a property to your third view controller so you can call the line:

[[self parentVC] dismissModalViewControllerAnimated:NO];

Note that parentVC is a property that should be set to point to the second view controller

Then when dismissing:

[self dismissModalViewControllerAnimated:NO];
[[self parentVC] dismissModalViewControllerAnimated:NO];

This will take you back to the first view controller.

The second, which is not really better or worse, but is probably easier to code, is to dismiss the second view controller before going to the third; again, you probably will not want to animate the view controllers between the transition from the second to the third, but you could animate from the third to the first.



来源:https://stackoverflow.com/questions/14840318/uiviewcontrollers-view1-view2-view3-displayed-in-succession

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