开发者

iPhone/iOS: Push Controller onto NavigationController that is currently not selected

开发者 https://www.devze.com 2023-03-08 22:06 出处:网络
Within my iPhone App I use a UITabBarController that holds four UINavigationController. Each UINavigationController represents a specific navigation within my app.

Within my iPhone App I use a UITabBarController that holds four UINavigationController. Each UINavigationController represents a specific navigation within my app.

Normally if I want to push a new controller onto the stack of the current UINavigationController I just do something like:

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

However there are a few places within my app, where the user is located within on navigationController and his action should change the selected Tab of the UITabBarController and push the controller there. I tried something like:

// 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];

But this approach doesnt work. The selectedIndex of the TabBar chances correctly, but the controllerToPush has not been added to the navigationController-Stack. What am I doing wrong?


Try doing

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号