2015-10-16 94 views

回答

0

試試這個 -

目前你在你的ThirdViewController,說你FirstViewController的類名是「FVC」。

NSArray *allViewControllers = [self.navigationController viewControllers]; 
for (UIViewController *aViewController in allViewControllers) { 
    if ([aViewController isKindOfClass:[FVC class]]) { 
     [self.navigationController popToViewController:aViewController animated:YES]; 
    } 
} 

這應該做的伎倆

編輯 -

歐普想解釋這是怎麼回事。

在您的導航堆棧中,當前有 - VC1,VC2,VC3(您現在是@ ​​VC3)。 接下來當你調用這個方法[self.navigationController popToViewController:vc1],你的導航堆棧中有VC1,因爲你是從VC3彈出到VC1,從而飛出的VC的一切,從而釋放你的記憶

+0

如果我使用這種方法,我如何釋放第二個viewController。 –

+0

檢查編輯PLZ,我希望你得到的概念,:) –

+0

我明白了,thx :) –

0

你可以使用導航方法。

[[self navigationController ] popToRootViewControllerAnimated:YES]; 

,或者你使用這個

popToViewController:(UIViewController *)viewController animated:(BOOL)animated; 

&傳遞要彈出控制器。

0

有針對

- (NSArray<__kindofUIViewController *> * _Nullable)popToRootViewControllerAnimated:(BOOL)animated 

的方法你需要做的是這樣

[self.navigationController popToRootViewControllerAnimated:YES]; 

請參考蘋果文檔:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/#//apple_ref/occ/instm/UINavigationController/popToRootViewControllerAnimated

+0

但我第一次的viewController不是我的根的viewController –

0

使用此行代碼 -

[self.navigationController popToRootViewControllerAnimated:YES]; 

或者使用這 -

NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]]; 
for (UIViewController *aViewController in allViewControllers) { 
    if ([aViewController isKindOfClass:[YourStoryBoardName class]]) { 
     [self.navigationController popToViewController:aViewController animated:YES]; 
    } 
} 
相關問題