English 中文(简体)
Switching a view
原标题:

I have a problem with switching views in an iPhone application. I have the source code of "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) - chapter 6 - Multiview Applications.

Now I have the problem, I want to create a new view which should switch by clicking the button on the blue screen "Press me". But it did not work.

I add the these lines to the IBAction that the button on the blue screen is pressed:

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

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

But the toolbar at the bottom won t disappear. But I want that this toolbar disappear.

If I wrote

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

instead of

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

the new xib lies behind the old one, so I see both views, the old and the new. Why? I do not understand this.

Thanks a lot in advance & Best Regards Tim

最佳回答

The toolbar is in the SwitchView so you would need to hide it from the view if you want it to hide. You could make an IBOutlet for the toolbar and then call setHidden:(BOOL) to hide it. You will need to do this from BlueViewController so you will need a way to get to your super view (which is SwitchView). You will also need to remove the BlueView from the super view by calling removeFromSuperView on blueViewController before inserting the new view into place. It is basically the same code that comes from the switch button in SwitchViewController.

Update: I looked at your code. In BlueViewController.m use this for blueButtonPressed:(id)sender

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

You will also need to add these two imports for "View_SwitcherAppDelegate.h" and "SwitchViewController.h".

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签