views:

710

answers:

1

I'd like to load a plain UIView, a UIWebView and a UITableView all in the same nib. Is that possible in the same UIViewController? Is it possible to assign multiple UIViewControllers to the same Window?

+1  A: 

Something close is possible. I recently answered your question about multiple views in one window; the approach for having multiple view controllers is very similar, although they do need separate nib or xib files.

The way to do it is as follows:

  1. Instantiate all the various controllers you need
  2. Add the view of each controller to the parent view or window, as I answered in your previous question

Programmatically, it would look something like (repeated for each view controller you want to add):

// With some UIWindow *window
MyViewController *vc = [[[MyViewController alloc] 
                         initWithNibName:@"MyNib" bundle:nil] autorelease];
[window addSubview:vc.view];

Keep in mind you may need to adjust the frame property of the view before you add it, depending on where in the parent view or window you want to place it.

Tim
Tim, thanks a lot. I didn't realize the relationship between the two questions. I see the correlation now.
Adam