Get StoryBoard instance of View Controller

20,202

You can give the view controller an identifier in interface builder, then simply use:

UIStoryboard *mystoryboard = [UIStoryboard storyboardWithName:@"myStoryBoardName" bundle:nil];
self.leftController = [mystoryboard instantiateViewControllerWithIdentifier:@"idyouassigned"];
Share:
20,202
1337code
Author by

1337code

Updated on July 20, 2022

Comments

  • 1337code
    1337code almost 2 years

    Example without storyboard:

    AppDelegate.h

    @property (retain, nonatomic) UIViewController *leftController;
    

    AppDelegate.m

    self.leftController = [[LeftViewController alloc] initWithNibName:@"LeftViewController" bundle:nil];
    

    OtherViewController:

    //This is what I want do to in storyboards
    self.viewDeckController.leftController = (AppDelegate*)[[UIApplication sharedApplication] delegate].leftController;
    

    How can I get that instance of leftController when using storyboards?

  • 1337code
    1337code over 11 years
    Wouldn't this return new view controller? I want to point to already created view controller.
  • Mick MacCallum
    Mick MacCallum over 11 years
    @1337code See my edit. I'm not sure if I'm understanding what you are trying to do. If in your app delegate you wish to create "leftController" with the contents of a view controller in a storyboard, you'll want to use the code I've provided.
  • 1337code
    1337code over 11 years
    Please take a look at this: github.com/Inferis/ViewDeck I want to use it with storyboard, check the description and how to change views.