2016-02-05 41 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

相關問題