[英]Pushing UINavigationController into UIViewController Using Storyboard
[英]Storyboard - Pop to Root UIViewController Without UINavigationController?
我有一個UIViewController
層次結構,它由一個根視圖控制器組成,該控制器分隔到一個UITabBarController
,它下面有幾個UIViewControllers
。 每個選項卡UIViewControllers
都有自己的UINavigationController
。 沒有共享的UINavigationController
,也沒有應用於Root View Controller。 現在我遇到一種情況,我需要從UIViewControllers
選項卡之一一直彈回Root View Controller。 但是,由於Root View Controller和UIViewControllers
選項卡不共享一個共同的UINavigationController
,我無法簡單地調用[self.navigationController popToRootViewControllerAnimated:YES]
。 是否可以在沒有共享的通用UINavigationController
情況下彈出Root View Controller(或以編程方式將我的Segues展開回根)
我有一次類似的問題,試試這個
UIStoryboard *storyBrd = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *controller = nil;
controller = [storyBrd instantiateInitialViewController];
self.view.window.rootViewController = controller;
這個初始視圖控制器是你的RootViewController。 否則你也可以使用這個方法
[storyBrd instantiateViewControllerWithIdentifier:<View Controller's Restoration ID>]
以下是我對vc安排的理解:
|-navvc
| |--rootvc-(pushes)-stack...
"root" vc-(presents)->tabvc--|
|-navvc
|--rootvc-(pushes)-stack...
只要您握住正確的把手,它就很容易解開所有這些。 選項卡中的導航vcs可以通過self.navigationController
在其堆棧上的任何視圖控制器上訪問。
你需要在標簽欄vc或你稱之為“root”vc的那個上有ahold。 您可以使用應用委托上的屬性進行安排。
要記住的唯一其他棘手的事情是,從“根”vc到標簽欄的過渡是一個禮物,而不是一個推動,所以它必須通過消除而不是彈出來撤消。 要在代碼中表達這一點,我們假設您已經掌握了應用程序委托上的標簽欄vc ....
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarVC;
- (void)popEverything:(BOOL)animated;
@end
// AppDelegate.m
// get the tab bars tabs (which are presumed to be navigation vcs)
// dismiss the tab bar vc (which was presumed to be presented)
// iterate the navigation vcs, popping all of them to root
- (void)popEverything:(BOOL)animated {
NSArray *viewControllers = self.tabBarVC.viewControllers;
[self.tabBarVC dismissViewControllerAnimated:animated completion:^{
for (UINavigationController *navVC in viewControllers) {
[navVC popToRootViewControllerAnimated:animated];
}
}];
}
警告適用:仍然猜測你的vc安排,並沒有測試前面的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.