2012-07-15 30 views
1

我有一個名爲UserInfoViewController一個UIViewController類,什麼時候會出現,這樣的parentViewControoler使用代碼:presentModalViewController和initWithRootViewController

UserInfoViewController *rvc = [[UserInfoViewController alloc] initWithNibName:@"UserInfoViewController" bundle:nil]; 
    rvc.user = user; 
    UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:rvc]; 
    nc.navigationBarHidden = YES; 
    [self presentModalViewController:nc animated:YES]; 
    [rvc release]; 
    [nc release]; 

有時UserInfoViewController將推動或呈現另一個視圖控制器,所以棧應該如:

Root VC 
    | 
    A (push) 
    | 
    | - B (present) 
      | 
      |-- C (push) 
       | 
       |- D (push) 
        | 
        |- E (present) 

B,E是類UserInfoViewController的。

問題是,當在視圖控制器E上時,我想關閉所有viewcontrollers並返回到Root VC,但我無法一次處理它們。

我試圖popToRootViewControllerAnimateddismissModalViewControllerAnimatedsetViewControllers,但他們沒有工作。

我也把通知偵聽,當需要返回根VC,剛剛張貼通知,並在監聽器選擇,這樣做:

[self.navigationController popToRootViewControllerAnimated:NO]; 
[self.presentingViewController dismissModalViewControllerAnimated:NO]; 

然後CD是封閉的,但** BE **仍然存在。

有什麼建議嗎?

回答

0

我明白了。

只是不考慮流行或解僱它,讓它去whit導航控制器的dealloc行動。

所以,當你想從屏幕上刪除所有視圖控制器,在應用程序委託:

self.window.rootViewController = nil; 

,當你需要再次顯示的東西:

navigationController = [[UINavigationController alloc] init]; 
navigationController.navigationBarHidden = YES; 
self.window.rootViewController = navigationController; 
[self.window makeKeyAndVisible]; 

就是這樣。

相關問題