0

I'm launching a view controller in my app with this code :

MyViewController *myViewController = [[MyViewController alloc] init];
[self.navigationController pushViewController:myViewController animated:YES];

However I don't know what design file my viewcontroller use to add a simple label to it. I don't know if it uses any design file(story board). I have story board file and I have assigned its class to my controller but does the above code launch the controller with the story board?
Thanks

m0j1
  • 4,067
  • 8
  • 31
  • 54

1 Answers1

1

Your myViewController does not connect to any xib file(design file)

You could connect your design file using this construct method of UIViewController.

- (instancetype)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle

For example:

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"Your_Design_File_Name" bundle:nil];
[self.navigationController pushViewController:myViewController animated:YES];
tounaobun
  • 14,570
  • 9
  • 53
  • 75
  • Thanks , is it also doable with story boards? – m0j1 May 15 '15 at 15:48
  • If you use storyboard, here is a link that might help you.http://stackoverflow.com/questions/19370208/how-to-connect-storyboard-to-viewcontroller – tounaobun May 15 '15 at 15:59
  • Thanks , and just initing the viewcontroller will be enough to launch it with story board design? – m0j1 May 15 '15 at 16:03
  • No,you don't have to create that view controller by code if you use storyboard. – tounaobun May 15 '15 at 16:11
  • Thanks, I'll appreciate if you give me a snippet on how to launch a story board – m0j1 May 15 '15 at 16:18
  • UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Your_Storyboard_Name" bundle:nil]; // initialize your storyboard UIViewController *initViewController = [storyBoard instantiateInitialViewController]; // get initial view controller. [self.navigationController pushViewController:initViewController animated:YES]; initial view controller is your storyboard's entry point view controller. – tounaobun May 15 '15 at 16:24
  • You can read more on this post: http://stackoverflow.com/questions/12536689/xcode-4-5-how-to-pick-storyboards-at-launch – tounaobun May 15 '15 at 16:25