2013-11-27 85 views
0

我有一個視圖控制器(MailServicesController),我已經模態地提出了。我想添加到這個MailServicesController一個UINavigationController(以編程方式),這將允許我推動和彈出另一個視圖控制器(LoginController)。我已經實現代碼來做到這一點,但我有兩個具體的問題:以編程方式創建的推送和彈出問題UINavigationController

  1. 導航控制器推loginViewController到堆棧的頂部,但即使我已經動畫BOOL設置爲不動畫這種轉變是在推送方法中。

  2. 一旦進入loginViewController,當我嘗試使用popViewControllerAnimated時,什麼事都沒有發生(我爲自己彈出了一個按鈕,我沒有使用導航控制器的導航欄)。

下面是我用它來創建的郵件服務模式視圖控制器內導航控制器代碼:在LoginController中

self.navigationController = [[UINavigationController alloc]init]; 
[self.navigationController willMoveToParentViewController:self]; 
self.navigationController.view.frame = self.view.frame; 
[self.view addSubview:self.navigationController.view]; 
[self addChildViewController:self.navigationController]; 
[self.navigationController didMoveToParentViewController:self]; 
[self.navigationController pushViewController:LoginController animated:YES]; 
//pushes login controller but with no animation 

然後,我嘗試彈出的LoginController頂掉,露出控制器我推:

- (void)dismissView //called by a button in my custom toolbar 
{ 

    UINavigationController *navigationController = (UINavigationController 
    *)self.parentViewController; //this is the navigationController I created 
    [navigationController popViewControllerAnimated:YES]; //is called but does nothing 
} 

我不知道我在做什麼錯,誰能看到我的錯誤?

+0

,你初始化UINavigation控制器或者其他地方 – codercat

+0

我只是初始化它在上面的代碼中 – jac300

+0

你想整個應用程序的導航或僅此兩類 – codercat

回答

0

雖然呈現模態到MailServicesController做這樣

MailServicesController *vc = [[MailServicesController alloc]init]; 
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:vc]; 
[self presentModalViewController:navController animated:YES]; 

之後,出示您的MailServicesController,現在它有

在MailServicesController同時推動loginViewController的UINavigationController

的所有屬性,只是使用

LoginViewController *vc = [[LoginViewController alloc]init]; 
[self.navigationController pushViewController:vc animated:YES]; 

雖然彈出LoginViewController

- (void)dismissView //called by a button in my custom toolbar 
{ 

    [self.navigationController popViewControllerAnimated:YES]; //is called but does nothing 
} 
+0

謝謝你,在我的init與MailServicesController導航控制器爲根,如果然後,我嘗試模態地呈現MailServicesController,它崩潰。 – jac300

+0

檢查我更新的答案。它應該工作。並且請刪除您用於在MailServicesController裏創建UINavigationController的代碼 –

+0

是的,謝謝! – jac300

相關問題