IOS - Interface building connectors not initialized

I created a view in Interface Builder with some labels and text as IBOutlets. I can see this screen perfectly when I navigate to it from another view that I defined in my storyboard. However, I have another XIB and an associated UIViewController that I want to access this view with. Since my XIB is not in the Storyboard, I cannot postpone it. Instead, I have to do the transition programmatically.

    PlantDetailViewController *plantDetailVC = [[PlantDetailViewController alloc] init];
    [self.currentNavigationController pushViewController:plantDetailVC animated:YES];


When this code is executed, it goes to the view, but the view is just empty. I was debugging the code and it injects viewDidLoad and viewWillAppear, however all my IBOutlets are NIL .... so nothing appears on the screen!

Can anyone tell me why they might be NIL and how can I initialize them?




source to share

2 answers

It looks like you are saying that you have PlantDetailViewController

one set in your storyboard and some OtherViewController

created outside of your storyboard. Now you want to OtherViewController

create an instance PlantDetailViewController

that has been set up in your storyboard.

Let's say your storyboard is called MainStoryboard.storyboard


First you need to set the id PlantDetailViewController

in the storyboard. You do this in the Attribute Inspector under Controller View. Let's say you installed it in PlantDetail


Then OtherViewController

this should work:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
PlantDetailViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"PlantDetail"];
[self.currentNavigationController pushViewController:vc animated:YES];





does not download the nib file for you if you want to download using nib -initWithNibName:bundle:

If you are using nib naming conventions, you can pass nil

to load nib whose name matches your default class and package, i.e. [[PlantDetailViewController alloc] initWithNibName:nil bundle:nil]

, see docs for -nibName




All Articles