2011-05-29 16 views
0

在我的iPhone應用程序中,我使用了一個包含四個UINavigationController的UITabBarController。每個UINavigationController代表我的應用程序中的特定導航。iPhone/iOS:將控制器推入NavigationController,目前未選中

通常情況下,如果我想要一個新的控制器推到當前的UINavigationController的堆棧我只是這樣做:

// push another controller onto the current NavigationController Stack 
MyController* controllerToPush = [[MyController alloc]init]; 
[self.navigationController pushViewController:controllerToPush animated:YES]; 
[controllerToPush release]; 

但也有我的應用程序,用戶所在內的內的幾個地方navigationController和他的動作應該改變UITabBarController的選定Tab並將控制器推到那裏。我試過類似的東西:

// Get a reference to my appDelegate 
MyAppDelegate* appDelegate = [[UIApplication sharedApplication] delegate]; 

// Change the selected Index of my TabBarController 
[[appDelegate tabBarController] setSelectedIndex:0]; 

// Get a reference to the NavigationController whose Index within the TabBarController is 0 
UINavigationController* navigationController = [appDelegate firstNavigationController]; 

// Push the newly initiliazed controller onto the navigationController 
MyController* controllerToPush = [[MyController alloc]init]; 
[navigationController pushViewController:controllerToPush animated:YES]; 
[controllerToPush release]; 

但是這種方法不起作用。 TabBar的selectedIndex機會正確,但controllerToPush尚未添加到navigationController-Stack。我究竟做錯了什麼?

+0

你確定'appDelegate.firstNavigationController'不是零? – albertamg 2011-05-29 18:17:39

+0

您能否提供一些來自應用程序委託的代碼? – LuckyLuke 2011-05-29 18:18:51

回答

0

嘗試做

[appDelegate.firstnavigationcontroller pushViewController:controllerToPush animated:YES]; 

+0

不,不適合我。你有沒有嘗試過,還是隻是猜測? – 2011-05-29 17:46:01

+0

是一個猜測。但我之前遇到過這種情況。但現在我不在我的Mac前面提及我使用的代碼。 :( – 2011-05-29 17:53:04

相關問題