在选项卡栏应用程序中弹出并推送视图

时间:2011-10-14 14:06:24

标签: iphone objective-c

我首先要展示这张照片,以便我可以参考它。

My application screenshot

基本上我想要实现的是你可以看到第一个选项卡被选中,并且正在显示一个视图。我有一个按钮,上面有一个“ - , - ”,我想要做的是,当点击该按钮时,它会弹出该选项卡中的视图,然后推送另一个视图。我可以通过这样做来改变视图:

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

但是我丢失了底部的标签:<如下例所示:

enter image description here

我不确定要朝哪个方向前进但是我已经尝试了这个但它失败了:

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

我也试过这个:

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

有人可以帮我吗?

2 个答案:

答案 0 :(得分:2)

使用导航控制器推送视图控制器是这样做的方法(你不能弹出你想要在这里做的根控制器),但是

UINavigationController *navController = self.navigationController;

如果视图控制器(self)有一个导航控制器,它只返回一些东西,它不在默认的标签栏应用程序中(检查navController是否为nil)。如果您查看MainWindow.xib,标签栏控制器应具有视图控制器项,将其更改为导航控制器并将其根视图控制器设置为您想要的。

答案 1 :(得分:1)

删除按钮和文本,将它们移动到新的UIView中。添加这个新的UIView作为子视图。该按钮应告诉控制器删除该子视图并添加另一个子视图。