PDA

View Full Version : How to switch between UIView?




Sergio10
May 4, 2009, 12:30 PM
Hi,
I have 2 UIView (main menu and playfield). need to switch between theese controls. For example when I press "menu" button should see UIView main menu control.

Ho to implement it?
As I understood I should bind to UIWindow control?
Tahnks



BlackWolf
May 4, 2009, 12:45 PM
there is no UIWindowController, is there?

Not quite sure what you mean though? If you want to "switch" between views you need to remove one from it's superview (removeFromSuperview-method) and then add the new view to the superview (probably the window if you are not using a tabbar) via the addSubview:-method, that's it.

Sergio10
May 4, 2009, 02:44 PM
I have next object in xib:
- UIWindow
- UIView1
- UIView2
- UIViewController

When run project I see UIWindow only. What exectly should I write for UIView switching? Should I delete UIWindow and use UIViewController and UIViews only?

Thanks

BlackWolf
May 4, 2009, 04:28 PM
I have next object in xib:
- UIWindow
- UIView1
- UIView2
- UIViewController

When run project I see UIWindow only. What exectly should I write for UIView switching? Should I delete UIWindow and use UIViewController and UIViews only?

Thanks

first of all, you should read the basics on what parts make an iphone app, because you cannot delete the UIWindow, it's necessary to display your application. Seems to me like you need to read the basics of objective-C in general.
When your application loads you need to add a subview (a UIView) to UIWindow that you want to be displayed (actually, you don't NEED to do that, but you should). It's good practice to nest that subview in a UIViewController. You need a second UIView that you want to get displayed later, and you need some kind of mechanic that switches between the two views (a button?). when the user wants to switch to the other view (presses the button?) you simply remove the view that is currently displayed in your windows via the removeFromSuperview method. after that, you add the new view to your window via addSubview - that's it.