开发者

Pop and push a view in a tab bar application

All me to show this picture first so I can make reference to it.

Pop and push a view in a tab bar application

Basically what I would like to achieve is as you can see the tab first has been selected, and a view is being displayed. I have a button which has a "-,-" on it, and what I would like to do, is when that button is clicked, it pops the view from this tab, and pushes another view. I am able to change the view by doing this:

FourthViewController *home = [[FourthViewController alloc] initWithNibName:@"FourthView" bundle:nil];
[self presentModalViewController:home animated:YES];
[home release];

But I lose the tabs down the bottom :< as the example below will show:

Pop and push a view in a tab bar application

I'm not sure which direction to head BUT I have tried this and it failed:

UINavigationController *navController = self.navigationController;
// retain ourselves so that the controller will still exist once it's popped off
[[self retain] autorelease];
// Pop this controller and replace with another
[navController popViewControllerAnimated:NO];
[navController pushViewController:home animated:NO];

I've also tried this:

FourthViewController *home = [[FourthViewController alloc] initWithN开发者_StackOverflow中文版ibName:@"FourthView" bundle:nil];
[self.navigationController pushViewController:home animated: YES];
[home release];

Can anybody help me with this?


Using the navigation controller to push view controllers is the way to do it (you can't pop the root controller which is what you seem to want to do here), however

UINavigationController *navController = self.navigationController;

Will only return something if the view controller (self) has a navigation controller, which it doesn't in the default tab bar application (check to see if navController nil). If you look in your MainWindow.xib, the tab bar controller should have view controller items, change those to navigation controllers and set their root view controllers to what you want.


Remove the button and the text, move them into a new UIView. Add this new UIView as a subview. The button should tell the controller to remove this subview and add the other one.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜