Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Matteo Gobbi

macrumors newbie
Original poster
Aug 23, 2008
2
0
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.
 

detz

macrumors 65816
Jun 29, 2007
1,051
0
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];
 

davedelong

macrumors member
Sep 9, 2007
50
0
Right here.
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.