Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

storyboard instantiateViewControllerWithIdentifier not setting IBOutlets

I am using storyboard instantiateViewControllerWithIdentifier: and I'm noticing that all the IBOutlets I have wired up are still nil. However, the IBActions I have wired up work. The view and controller are linked (i.e controller.view is not nil), and if I show the view it displays what I am expecting.

What am I missing?

Here's my setup:

  1. I've got a View Controller defined in my storyboard. I have given it an identifier which is the same identifier I use when invoking instantiateViewControllerWithIdentifier:
  2. I've set up the view's owner by clicking on the View Controller (just under First Responder) and under the Identity Inspector set the Custom Class to be the same name as the class I want to wire the view to.
  3. Then I open up Assistant editor, and control dragged the UI elements to create the IBOutlets and IBActions.
like image 783
BlueFish Avatar asked Sep 21 '12 01:09

BlueFish


2 Answers

The view seems to be initialized properly only after it is accessed first. The problem goes away when calling

[self presentViewController:vc animated:NO completion:nil]; 

or more simply

[vc view]; 
like image 132
Stefan Henze Avatar answered Oct 01 '22 07:10

Stefan Henze


[Use me as bad example]

Maybe not a good idea after all, it works but it violates the regular loading making the app unstable ^_^.
I'll leave the answer here in case someone else want to know if you do it.


I was having the same issue, however the custom component I designed isn't loaded via presentViewController (load in overlay to the previous view)

You can simply call

myViewController.loadView() //Swift

[myViewController loadView] //Obj-C

like image 29
Cesar Avatar answered Oct 01 '22 07:10

Cesar