本文介绍了UINavigationController , pushViewController 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个视图控制器

I have 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 是我的第二个视图控制器.这两个视图通过推送转场连接.

ViewControllerSearch id my second view controller.these two view s connected with push segue.

当我点击按钮时出现此错误.

when i click the button coming this error.

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

我该如何修复这个错误?请给我想法.

how can i fixed this error?please give me idea.

推荐答案

你确定你的 Nib 叫做ViewControllerSearch.xib"?

Are you certain your Nib is called 'ViewControllerSearch.xib'?

此外,您不需要清除 vc3New - 事实上您可能不应该这样做.

Also you don't need to nil out vc3New - in fact you probably shouldn't.

更新

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

...to load from a storyboard, as mentioned in the comment, you need to do something like this:

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

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

1) Make to sure the storyboard identifier matches what you've named it2) Make sure you've set/used the correct identifier, in the storyboard, for your controller

这篇关于UINavigationController , pushViewController 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 18:01