Open new view from actual view

Discussion in 'iPhone/iPad Programming' started by Matteo Gobbi, Aug 23, 2008.

  1. macrumors newbie

    Joined:
    Aug 23, 2008
    #1
    Hi,
    i'm italian and excuse me if i do error.

    I have 3 view: MAINVIEW, VIEW1, VIEW2.
    A MAINVIEW is the principal view, and when applications is loades I connect a VIEW1 to it with [mainview addSubView:view1].

    Well,
    now i want that when I click one my button and a method start, it open a new view: VIEW2.

    My view are designed by InterfaceBuilder (.xib file).

    How must i do to initializate and open this VIEW2?

    Thanks,

    please you write a easy english thanks.
     
  2. thread starter macrumors newbie

    Joined:
    Aug 23, 2008
    #2
    thanks
     
  3. macrumors 65816

    Joined:
    Jun 29, 2007
    #3
    You need to make a connection to that view in Xcode.

    IBOutlet UIView *view2;

    ....

    Then link that view to the actually view in Interface Builder. You can then add it just like you added view1.

    [view1 removeFromSubview];
    [mainView addSubView:view2];
     
  4. macrumors member

    davedelong

    Joined:
    Sep 9, 2007
    Location:
    Right here.
    #4
    Alternatively, if you have View1 and View2 in different .xib files, you'll need to either:
    1. Load the views using the [NSBundle mainBundle] object or
    2. Creating a subclass of UIViewController to manage that particular .xib, then instantiate the UIViewController using initWithNibNamed:bundle: The class of the "File's Owner" in that .xib would be the same as your subclass of UIViewController. To get the view to load as a subview, you'd hook the view to the File's Owner (your UIViewController), and then (in code) do:
    Code:
    [window addSubview:[myView1Controller view]];
    Personally, I prefer the second method as I understand what it's doing a bit better.

    HTH,

    Dave
     

Share This Page