1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

How to switch between UIView?

Discussion in 'iPhone/iPad Programming' started by Sergio10, May 4, 2009.

  1. macrumors regular

    #1
    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
     
  2. macrumors regular

    #2
    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.
     
  3. macrumors regular

    #3
    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
     
  4. macrumors regular

    #4
    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.
     

Share This Page