0

I'm trying to push the Navigator Controller to a different view controller but I keep getting the error saying the nib bundle name can't be loaded. Here's the code I'm using:

SecondViewController *vc1 = [[SecondViewController alloc]
      initWithNibName:NSStringFromClass([SecondViewController class]) bundle:Nil];
[self.navigationController pushViewController:vc1 animated:YES];
DrummerB
  • 39,814
  • 12
  • 105
  • 142
Destiny Dawn
  • 1,457
  • 3
  • 15
  • 29

1 Answers1

1

You have to pass the name of the nib file, not the class name:

// Assuming there is a properly set up SecondViewController.xib in your project.
SecondViewController *vc1 = [[SecondViewController alloc] 
                            initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:vc1 animated:YES];

EDIT:

If you're using Storyboards, you have to load your GUI a bit differently:

UIStoryboard *sboard = [UIStoryboard storyboardWithName:@"StoryboardFileName" 
                                                 bundle:nil];
SecondViewController *vc1 = [sboard instantiateInitialViewController];
DrummerB
  • 39,814
  • 12
  • 105
  • 142
  • I've tried just doing that but I still get the error. Here's the entire error: 2012-09-15 20:07:45.127 Passdata.app[4010:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'SecondViewController'' *** First throw call stack: – Destiny Dawn Sep 16 '12 at 00:08
  • Is there a SecondViewController.xib in your project and added to your target? – DrummerB Sep 16 '12 at 00:11
  • I'm using a storyboard so I don't have a xib file, could that be causing the problem? – Destiny Dawn Sep 16 '12 at 00:12
  • that fixed that problem but I'm also passing a string to the SecondViewController so I'm getting this error now, would you know anything about it?: 2012-09-15 20:28:10.942 Passdata.app[4083:907] -[UINavigationController setTmpString:]: unrecognized selector sent to instance 0x1d57f530 2012-09-15 20:28:10.946 Passdata.app[4083:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setTmpString:]: unrecognized selector sent – Destiny Dawn Sep 16 '12 at 00:29
  • Do you research before asking? I can't debug your whole app... http://stackoverflow.com/questions/861626/how-to-resolve-unrecognized-selector-sent-to-instance http://stackoverflow.com/questions/2455161/unrecognized-selector-sent-to-instance http://stackoverflow.com/questions/622865/how-do-i-debug-an-unrecognized-selector-sent-to-instance-problem – DrummerB Sep 16 '12 at 00:39
  • Yeah, I looked up my error but I couldn't find any results. Most things came up were completely irrelevant. – Destiny Dawn Sep 16 '12 at 00:41
  • 1
    @StørmShadøws, The error is saying that you're trying to call setTmpString on UINavigationController -- you should be calling it on SecondViewController – rdelmar Sep 16 '12 at 03:04