4

I run into the following problem. In my iPad app using storyboard.

-(UIViewController *)SetDetailVideoView
{
    // assign/instantiate self. storyboard, but how?
    VideosViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VideoViewController"]; //empty but why? Because self.storyboard is empty
    NSLog(@"%@",self.storyboard); //NULL
    return vc;
}

Self.storyboard returns nil so everything it try to get return nil and gives an exemption? So how do i instantiate self.storboard.

Msmit1993
  • 1,710
  • 4
  • 21
  • 35

2 Answers2

5

Use below code to instantiate your storyboard

self.storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
Hemant Singh Rathore
  • 2,153
  • 1
  • 24
  • 38
  • 1
    Just found the answer myself. but here you go, i checked your answer as right. – Msmit1993 Sep 19 '13 at 09:56
  • What was the problem? – Hemant Singh Rathore Sep 19 '13 at 10:07
  • The line of code was the solution it needed a specification of storyboard with name. I found the same solution as you suggested. Sorry i didn't make that clear, english isn't that easy. – Msmit1993 Sep 19 '13 at 10:33
  • Can anyone help with this? http://stackoverflow.com/questions/38959445/astoryboard-instantiateviewcontrollerwithidentifiermyid-returns-nil-but-not?noredirect=1#comment65274351_38959445 – harmeet07 Aug 18 '16 at 11:09
2

I don't like the hard coded style. You can also use:

[self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"VideoViewController"];
d.ennis
  • 3,445
  • 2
  • 28
  • 36
  • This one worked for me when self.storyboard didn't. Not entirely sure what the logic is, it's probably linked to how the view controller is instantiated. It's worth noting self.navigationController will be nil if a view controller was modally presented, so this wouldn't work in those instances. – Mark Bridges Aug 25 '15 at 08:35