UINavigationController,pushViewController错误

时间:2013-11-05 14:48:11

标签: ios uinavigationcontroller pushviewcontroller

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

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

1 个答案:

答案 0 :(得分:1)

你确定你的Nib被称为'ViewControllerSearch.xib'吗?

此外,您不需要将vc3New排除在外 - 实际上您可能不应该这样做。

已更新

...要从故事板加载,如评论中所述,您需要执行以下操作:

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

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