0

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.

2
  • It can't find the 'ViewControllerSearch'. Commented Nov 5, 2013 at 14:51
  • try to set the File´s owner of the Nib to ViewControllerSearch Commented Nov 5, 2013 at 14:55

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

it is in storyboad.not a xib
That's probably your issue. You have to use a method on the storyboard to manually create the storyboard based VC. You can't just directly alloc init it.
Thank you very much.yes it is identifier issue.It fixed usig this code.ViewControllerSearch *vc3New = [self.storyboard instantiateViewControllerWithIdentifier:@"vcsearch"];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.