UINavigationController , pushViewController Error

纵饮孤独 提交于 2019-12-12 00:44:09

问题


I have 2 view controller

VC1 has button

in this button action

   - (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 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.


回答1:


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

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

UPDATED

...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) Make to sure the storyboard identifier matches what you've named it 2) Make sure you've set/used the correct identifier, in the storyboard, for your controller



来源:https://stackoverflow.com/questions/19791724/uinavigationcontroller-pushviewcontroller-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!