我有 2 个 View Controller
VC1有按钮
在此按钮操作中
- (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 我的第二个 View Controller 。这两个 View 通过推送连接连接。
当我单击按钮时出现此错误。
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 清零 - 事实上您可能不应该这样做。
更新
...如评论中所述,要从 Storyboard加载,您需要执行以下操作:
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
ViewControllerSearch* controller = [storyBoard instantiateViewControllerWithIdentifier:@"ViewControllerSearch"];
1) 确保 Storyboard标识符与您为其命名的内容相匹配 2) 确保您在 Storyboard 中为您的 Controller 设置/使用了正确的标识符
关于ios - UINavigationController , pushViewController 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19791724/