UINavigationController,pushViewController错误

我有2个视图控制器

VC1有button

在这个button动作

- (IBAction)clickSearch:(id)sender { NSArray *vc=[self.navigationController viewControllers]; ViewControllerSearch *vcSearch=nil; for (int i=0; i<[vc count]; i++) { UIViewController *tempVC=[vc objectAtIndex:i]; if([tempVC isKindOfClass:[ViewControllerSearch class]]) { vcSearch=[vc objectAtIndex:i]; break; } } if(vcSearch) { [self.navigationController popToViewController:vcSearch animated:YES]; } else { ViewControllerSearch *vc3New= [[ViewControllerSearch alloc]initWithNibName:@"ViewControllerSearch" bundle:[NSBundle mainBundle]]; [self.navigationController pushViewController:vc3New animated:YES]; vc3New = nil; } } 

ViewControllerSearch id我的第二个视图控制器。这两个视图与push segue连接。

当我点击这个错误的button。

  Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/Ravi/Library/Application Support/iPhone Simulator/6.0/Applications/42268111-F290-40B8-B893-4649852F762C/coffee break app.app> (loaded)' with name 'ViewControllerSearch'' 

我该如何解决这个错误?请给我一个主意。

你确定你的Nib叫做“ViewControllerSearch.xib”吗?

你也不需要删除vc3New – 事实上你可能不应该这样做。

更新

…从评论板中加载,如评论中提到的,你需要做这样的事情:

 UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; ViewControllerSearch* controller = [storyBoard instantiateViewControllerWithIdentifier:@"ViewControllerSearch"]; 

1)确保故事板标识符与您命名的相匹配2)确保您已经在故事板中为您的控制器设置/使用了正确的标识符