9

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
  • 169
  • 1
  • 3
  • 11

2 Answers2

28

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"];
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
  • 13
    Wouldn't this return new view controller? I want to point to already created view controller. – 1337code Dec 06 '12 at 15:50
  • @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. – Mick MacCallum Dec 06 '12 at 15:55
  • Please take a look at this: https://github.com/Inferis/ViewDeck I want to use it with storyboard, check the description and how to change views. – 1337code Dec 06 '12 at 15:57
0

I am not sure whether you able to get solutions of this problem or not, but you can also refer the answer of this question :

Accessing view controller form a storyboard

Community
  • 1
  • 1
Amitg2k12
  • 3,765
  • 10
  • 48
  • 97