tags:

views:

725

answers:

2

I have a scrollview I'm trying to add ViewControllers to from a nib file.

ViewController *controller=[[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];
[scrollview addSubview:controller];

Scrollview is defined elsewhere.

Whenever I add other items like UIViews with simple colored backgrounds, that works fine. When I add the ViewController from the nib, the Viewdidload gets hit, the images load from the nib, but then the controller code stops there (No viewWillAppear etc). So I don't get any of the controller's processing.

This same controller works fine when pushed as a nav or tab controller. I'm sure I'm missing something in my educational process, but was hoping someone could help out so I can move on.

BTW: The ViewController above is a simple UIViewController.

A: 

OK, seems a little off, but I added viewWillAppear to viewDidLoad, and that worked, but this doesn't seem the right way to do it, correct?

jj
+2  A: 

I think your issue is that addSubview is expecting a UIView not a UIViewController - you probably get a warning when compiling ('may not respond to selector' or similar?). If so, don't just ignore those - in my experience, usually they are a problem in your code :-)

You could try something like

[scrollview addSubview:controller.view];

But this still won't get you the viewcontroller's processing ...you need to do that processing in the view controller that has the scrollview AFAIK. I would suggest trying to get a basic view with a scrollview working in IB first.

frankodwyer