I have a main view with a controller and two seperate view controllers with their own xibs.
something like
@interface MainViewController : UIViewController
{
FirstViewController* firstController;
SecondViewController* secondController;
}
I would like to have FirstViewController.xib and SecondViewController.xib so that I can put whatever I want in there.
N开发者_C百科ow in MainViewController.xib I want to be able to define the frames for the FirstViewController and SecondViewController.
Is the only way to do this to go into MainViewController's viewDidLoad
method and manually add the controller's respective views as subviews? But then how do I define the sizing???
One thing to remember is UIViewController
(and any subclass thereof) is a Controller
class (in the Model-View-Controller sense) and thus is not explicitly considered a view. UIViewController
however owns a view, and that is what you want here.
What you would do then, is in your MainViewController
's view (which you lay out with InterfaceBuilder and save as a xib file) you can create two temporary dummy UIView
s as placeholders, and add outlets to them in your MainViewController class. Connect these outlets in IB. You'll also want to keep around your instance variables for First and SecondViewController in your MainViewController header (this isn't explicitly needed but you'll probably want to hang on to these guys).
Then, in -viewDidLoad
of MainViewController
, you'll want to instantiate both First and SecondViewController (firstController = [[FirstViewController alloc] initWithNibName:@"myName.xib" bundle:nil];
, same for second), and then replace your dummy subviews (the ones you created in IB as placeholders) like so [[self view] replaceSubView:firstDummy withOtherView:[firstController view]];
).
That should do you. You might also want to exchange the autoresizingMask of the dummyViews with that of your controller views, too.
精彩评论