ios - UINavigationController , pushViewController 错误

标签 ios uinavigationcontroller pushviewcontroller

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

相关文章:

iphone - 如何使用 popToViewController 发送字符串值

ios - 导航栏标题对齐

ios - 无法推送 View Controller

ios - 无法推送 viewController,因为 navigationController 为 nil

ios - 使用 Swift 更新 Core Data 中的多对多关系

ios - [ios]更改导航栏后退按钮的标题

ios - 在 iOS : what is the difference between capturing video using AVMovieFileOutput or AVAssetWriter? 上捕获视频

ios - 显示最后推送的 Controller 的选项卡栏 Controller - swift 4

ios - 触摸按钮时无法将 View Controller 插入滑出菜单

ios - Realm 中的动态属性