0

我有 2 个视图控制器

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 我的第二个视图控制器。这两个视图与 push segue 连接。

当我单击按钮时出现此错误。

    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''

我该如何解决这个错误?请给我一个想法。

4

1 回答 1

1

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

此外,您不需要取消 vc3New - 事实上您可能不应该这样做。

更新

...要从情节提要加载,如评论中所述,您需要执行以下操作:

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

1)确保情节提要标识符与您命名的内容匹配 2)确保您在情节提要中为您的控制器设置/使用了正确的标识符

于 2013-11-05T14:53:57.810 回答