Shucheng Shucheng - 6 months ago 34
iOS Question

Could not load NIB in bundle: 'NSBundle ··· with name 'chosenCountry''

I want touch the

UIBarButtonItem
in the top right, and push a new viewController. So, the code is:

UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;


and method
insertNewObject
is:

-(void)insertNewObject{
chosenViewController *chosenCountry = [[chosenViewController alloc]initWithNibName:@"chosenCountry" bundle:nil];
//self.chosenViewController = chosenCountry;
[self.navigationController pushViewController:chosenCountry animated:YES];
}


but XCode have a error when I run 'Could not load NIB in bundle: 'NSBundle ...(loaded)' with name 'chosenCountry''
How can I fix it?
Thanks!

Answer
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
 UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"chosenCountry"];
 [self.navigationController pushViewController:vc animated:YES];