2009-12-03 217 views
0

我在切换iPhone应用程序中的视图时遇到了问题。 我有“Beginning iPhone 3 Development”(http://books.google.com/books?id=TcP2bgESYfgC&printsec=frontcover&dq=beginning+iphone+3+development#v=onepage&q=beginning%20iphone%203%20development&f=false) - 第6章 - 多视图应用程序的源代码。切换视图

现在我有这个问题,我想创建一个新的视图,应该通过点击蓝色屏幕上的按钮“按下我”来切换。但它没有奏效。

我添加了这些行到IBAction为,蓝色屏幕上的按钮被按下:

StartViewController *startController = [[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil]; 
self.startViewController = startController; 

[self.view insertSubview:startController.view atIndex:1]; 
[startController release]; 

但在底部的工具栏将不会消失。但我希望这个工具栏消失。

如果我写

[self.view insertSubview:startController.view atIndex:0]; 

代替

[self.view insertSubview:startController.view atIndex:1]; 

新的厦门国际银行的背后是旧人,所以我看到这两个观点,旧的和新的。 为什么?我不明白。

感谢很多提前&此致添

回答

1

工具栏是在通过SwitchView所以你需要从视图中隐藏它,如果你想让它隐藏。您可以为工具栏创建一个IBOutlet,然后调用setHidden:(BOOL)来隐藏它。您将需要从BlueViewController执行此操作,因此您需要一种方法来访问您的超级视图(即SwitchView)。在将新视图插入到位之前,您还需要通过调用blueViewController上的removeFromSuperView从超级视图中删除BlueView。它基本上与SwitchViewController中的开关按钮相同。

更新: 我看着你的代码。在BlueViewController.m用这个blueButtonPressed:(ID)发送

StartViewController *start = [[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil]; 
self.startViewController = start; 
[start release]; 
View_SwitcherAppDelegate *appDelegate = [UIApplication sharedApplication].delegate; 
SwitchViewController *switchController = appDelegate.switchViewController; 
switchController.theToolbar.hidden = YES; 
[self.view removeFromSuperview]; 
[self.view insertSubview:startViewController.view atIndex:0]; 

您还需要添加这两种进口“View_SwitcherAppDelegate.h”和“SwitchViewController.h”。

+0

我整合了IBOutlet UIToolbar * theToolbar;和 @property(nonatomic,retain)UIToolbar * theToolbar; 到SwitchViewController.h并合成它。 我从“MainWindow”中的“Switch View Controller”切换到“theToolbar”。 并且用这几行代码: \t \t StartViewController * start = [[StartViewController alloc] initWithNibName:@“StartViewController”bundle:nil]; \t self.startViewController = start; \t [开始发布]; \t [self.view removeFromSuperview]; \t [self.view insertSubview:startViewController.view atIndex:0]; \t [theToolbar setHidden:YES]; 我得到错误,“工具栏未声明”。 – Tim 2009-12-04 11:02:46

+0

这是我最新的项目源代码: ud05_188.ud05.udmedia.de/spotlight/Project.zip – Tim 2009-12-04 11:17:39

+0

这是行不通的。下一个屏幕“StartVireController.xib”上有一个文本标签。但屏幕是白色的。 – Tim 2009-12-08 16:30:39