2015-02-10 78 views
1

我有多個UINavigationControllers如何彈出到根視圖控制器與視圖層次包含多個導航控制器

從一個特定的視圖控制器

現在視圖層次,我想彈出到window.rootviewcontroller

我該怎麼做?

我試圖

[UIApplication的sharedApplication] .keyWindow.rootViewController popToRootViewController];

但它不起作用。請建議。

請注意我想要去window.rootVC。

這不會爲我工作

[self.navigationController popToRootViewControllerAnimated:YES]; 

回答

2

只是獲取窗口實例,並重新設置根視圖控制器,爲popToRootViewController只彈出到根視圖特別導航堆棧控制器

- (void)popToRoot 
{ 
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
    UIWindow *mainWindow = appDelegate.window; 
    ViewController *viewControllerObj = [ViewController new]; 
    UINavigationController *navigationObject = [[UINavigationController alloc] initWithRootViewController:viewControllerObj]; 
    [mainWindow setRootViewController:navigationObject]; 
} 

希望這會有所幫助。

2

設置

UINavigationController *navController = (UINavigationController*)self.window.rootViewController; 


[self.navigationController popToRootViewControllerAnimated:YES]; 
+0

它將採取當前導航控制器的根視圖控制器....我想去window.rootviewcontroller – GJain 2015-02-10 08:05:05

相關問題