0

I have a XIB file in which I have a few UI elements. The resulting view is controlled by my own class derived from UIViewController. This one works fine, and viewDidLoad is called, when the XIB file gets loaded etc from the main application delegate.

However, in that XIB file I also have (obviously) some sub views. One of them is a UITableView. That one is being controlled by a custom class of mine derived from UITableViewController. I've set the delegate, datasource outlets on the one side, the UITableViewController also has got the correct view property set. However, the viewDidLoad of the UITableViewController is NOT called when the surrounding view loads.

I think this because the main UIView / UIViewController pair does not really know about the subview. in the UIViewController viewDidLoad I can call the subview's viewDidLoad. However I am suspecting that this is not the intended usage. So what should I do instead?

What I was assuming was, that subviews loaded from a xib file all get the viewDidLoad message.

Arne
  • 2,624
  • 3
  • 24
  • 45

1 Answers1

3

You're correct in that you shouldn't call the subview's viewDidLoad: method, as it should always get called when the view is loaded (regardless of how the view is created). From the documentation:

This method is called regardless of whether the views were stored in a nib file or created programmatically in the loadView method.

This suggests to me that something (connections?) haven't been set up correctly in your .xib file, or that the controllers haven't been properly linked with their views. When you say that the UITableViewController has the correct view set, are you using the "view" property instead of the "tableView" property of the UITableViewController...?

James Bedford
  • 28,702
  • 8
  • 57
  • 64
  • Hm, in the IB I can only see the view property of my derived class. But you're right! I probably should be using tableView instead. I will check where that one went... – Arne Mar 08 '11 at 15:27
  • Hm, strange. The only outlets I get in IB are SearchController and view, for the class derived from UITableViewController... – Arne Mar 08 '11 at 15:30
  • Maybe this will help. http://stackoverflow.com/questions/2265029/how-do-i-add-an-uiview-above-a-tableviewcontroller – James Bedford Mar 08 '11 at 15:46
  • Thanks! that does look helpful – Arne Mar 09 '11 at 10:32