无法在包中加载NIB:'NSBundle ... with name'chosenCountry''
我想触摸右上角的UIBarButtonItem
,然后推送新的viewController。所以,代码:无法在包中加载NIB:'NSBundle ... with name'chosenCountry''
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
和方法insertNewObject
是:
-(void)insertNewObject{
chosenViewController *chosenCountry = [[chosenViewController alloc]initWithNibName:@"chosenCountry" bundle:nil];
//self.chosenViewController = chosenCountry;
[self.navigationController pushViewController:chosenCountry animated:YES];
}
但XCode中有一个错误,当我运行“捆绑无法加载NIB: '一个NSBundle ...(加载)'与名称'chosenCountry'' 我该如何解决它? 谢谢!
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"chosenCountry"];
[self.navigationController pushViewController:vc animated:YES];
它与我一起工作,非常感谢! – Shucheng
欢迎@舒城:-) –
既然你添加了你的vc故事板,因此initWithNibName
将无法正常工作。
要么使用segue
或使用故事板的方法instantiateViewControllerWithIdentifier
实例化视图控制器
谢谢!我会试试! – Shucheng
使用此代码,它为你工作
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
yourViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"chosenCountry"];
[self.navigationController pushViewController:vc animated:YES];
是啊!它与我合作,但Bhadresh Mulsaniyaa首先回答,对不起:) – Shucheng
你有一个名为'chosenCountry'一个XIB文件? – Larme
我认为你的viewconrtoller名称是selectedViewController.try这个chosenViewController –
@Larme我不知道,我拖动一个新的视图控制器在storyboard中,并将其设置在selectedViewController类中。我该怎么办?非常感谢你 – Shucheng