2016-02-05 54 views

回答

1

不,您不必重新实例化它。您可以从UINavigationController访问所有当前UIViewControllers这样

self.navigationController?.viewControllers 

这将返回一个[UIViewController]。如果你想获得viewController它在index = 0。如果你想回到root您可以拨打

self.navigationController?.popToRootViewControllerAnimated(true) 
+0

你怎么去分配视图位指示?通过'dismissViewControllerAnimated(...)'?那会从根本上“销毁”视图控制器直到它被重新实例化吗? – MikeG

+1

'presentViewControllerAnimated()'和'popViewControllerAnimated'被用于返回'UINavigationController'的viewcontroller堆栈中的一个viewController时使用'dismissViewControllerAnimated()'。是的两种情况(解雇/流行)解除分配和销毁viewController –

+0

你假设他的UIViewController嵌入在导航控制器中,但并非总是如此。 –

1

我已经添加了这是一个评论,只是我没有足够的积分。 要回答你的问题 - 你不必担心重新实例化先前的视图控制器。如果您使用的是presentViewController:animated:completion方法,则可以使用UIViewController类中的presentedViewControllerpresentingViewController属性,这些属性在转换后设置。

开发商下面的链接将帮助您决定如何根据你的使用情况来处理视图控制器过渡更好 -

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instp/UIViewController/presentedViewController

相关问题