我正试图从Objective-C类推送ViewController,如下所示:
ProductDetailVC *aObjVC = [appDelegate.mainStoryBoard instantiateViewControllerWithIdentifier:@"ProductDetailVC"];
[self.navigationController pushViewController:aObjVC animated:YES];
但是由于以下原因它崩溃了:
"因未捕获的异常而终止应用 ' NSInvalidArgumentException',原因:' Storyboard()不包含带标识符的视图控制器 ' ProductDetailVC''"
我甚至分配了标识符" ProductDetailVC"在故事板中
答案 0 :(得分:0)
您是否检查过您的故事板是否为零?
试试这个:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"YOURSTORYBOARDNAME"
bundle: nil];
YOURVIEWCONTROLLER *controller = (YOURVIEWCONTROLLER*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"YOURVIEWCONTROLLERID"];
答案 1 :(得分:0)
最可能的原因是,您的appDelegate.mainStoryBoard
没有对您的实际故事板的引用。您不需要在appdelegate中保留故事板引用来推送视图控制器。您可以通过调用self
代替
ProductDetailVC *aObjVC = [self.mainStoryBoard instantiateViewControllerWithIdentifier:@"ProductDetailVC"];
[self.navigationController pushViewController:aObjVC animated:YES];
答案 2 :(得分:0)
ProductDetailVC * productDetailVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ProductDetailVC"];
[self.navigationController pushViewController:productDetailVC animated:TRUE];