1

I've set up a container view inside my my main view controller. I configured this through interface builder. The main view controller holds the container view, and I have custom class (derived for from UIViewController) to handle the work in the container view's controller. I've laid out all the widgets in the container view, and all works well. Now, I've found a case where I'd like to re-use that same code in a different view controller.

So I started with the following to verify the code was being hit:

    iPad_Expansion_ContViewController *kaufer = [iPad_Expansion_ContViewController new];
    [gameController addChildViewController:kaufer];

    kaufer.view.frame = CGRectMake(100, 200, 500, 500);
    kaufer.view.backgroundColor = [UIColor blueColor];

    [gameController.view addSubview:kaufer.view];
    [gameController.view bringSubviewToFront:kaufer.view];

    [kaufer didMoveToParentViewController:gameController];

This does indeed create a big blue box; however, how do I load the contents of the containerViewController I defined through interface builder? I think I need something like the following, but I don't know where to find the NIB name created via Interface Builder.

    iPad_Expansion_ContViewController *kaufer = [[iPad_Expansion_ContViewController alloc] initWithNibName:@"???????" bundle:[NSBundle mainBundle]];
    [gameController addChildViewController:kaufer];
    [kaufer didMoveToParentViewController:gameController];

From all of my web searching, it seems that finding the NIB name is trivial and obvious. But I'm still missing something... I tried using the name of the story board; however, all of the objects in kaufer were nil, and no view appeared on the screen.

Thunk
  • 4,099
  • 7
  • 28
  • 47

1 Answers1

0

Well, this has been a very trying afternoon. I wasn't crazy (at least not in this matter) after all: it's orders of magnitude more difficult to find the .xib name viewControllers in a storyboard as of Xcode 6.4 than in prior versions. These two questions didn't completely solve the problem, but they provided the main clues that got me moving again:

Use initWithNibName with a storyboard

STORYBOARD - doesn't contain a view controller with identifier (khaliq's answer)

And without further ado, I unleash upon the Internet the (functioning) following code snippet:

    UIStoryboard *storyboard = self.storyboard;
    myCustomContViewController *kaufer = (myCustomContViewController *)[storyboard instantiateViewControllerWithIdentifier:@"shopper"];
    [mainController addChildViewController:kaufer];

    [mainController.view addSubview:kaufer.view];
    [mainController.view bringSubviewToFront:kaufer.view];

    [kaufer didMoveToParentViewController:mainController];
Community
  • 1
  • 1
Thunk
  • 4,099
  • 7
  • 28
  • 47