0

I have a ViewController in Interface Builder that has a TableViewController embedded in it (I reuse the functionality of the TableViewController elsewhere). I need to set a delegate in the TabelViewController back to the UIViewController it is embedded in so that I can use the NavigationController of the UIViewController (click on row in embedded TableViewController, new ViewController appears....).

I've got a delegate to make this all work, the only problem I have is where to set the delegate. I had read that awakeFromNib gets called once a nib is read in and all IBOutlets have been set (the embedded TableViewController is an IBOutlet). I can step through the code and see that this function is called when the app first launches. However, when I later call the delegate (when a row is clicked), the delegate is null. If I set the delegate in viewDidLoad, everything works great.

Any ideas why awakeFromNib isn't working? Should I be doing this in viewDidLoad anyway?

Thanks!

Tyler DeWitt
  • 23,366
  • 38
  • 119
  • 196

1 Answers1

0

You can read more about why your awakeFromNib method is not working properly here: Why won't my awakeFromNib fire?

The viewDidLoad method is a perfect place for setting the UITableViewDelegate no actual benefits from setting it in other methods.

Community
  • 1
  • 1
Or Ron
  • 2,313
  • 20
  • 34