0

I am trying to push ViewController from Objective-C class as bellow:

ProductDetailVC *aObjVC = [appDelegate.mainStoryBoard instantiateViewControllerWithIdentifier:@"ProductDetailVC"];

[self.navigationController pushViewController:aObjVC animated:YES];

But it getting crashed due to below reason:

"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier 'ProductDetailVC''"

I even assigned identifier "ProductDetailVC" in storyboard

enter image description here

Nirav Patel
  • 432
  • 6
  • 19

3 Answers3

0

Did you check if your storyboard isn't nil?

Try this:

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"YOURSTORYBOARDNAME"
                                                         bundle: nil];

YOURVIEWCONTROLLER *controller = (YOURVIEWCONTROLLER*)[mainStoryboard 
                    instantiateViewControllerWithIdentifier: @"YOURVIEWCONTROLLERID"];
Nazmul Hasan
  • 10,130
  • 7
  • 50
  • 73
Pedro Pinho
  • 652
  • 3
  • 6
  • Storyboard isn't nil, i am calling other objective c classes from this inside main storyboard all works only in case of swift class not working. – Nirav Patel Jul 16 '17 at 17:35
0

Most probably the cause is, your appDelegate.mainStoryBoard does not holds a reference to your actual storyboard. You don't need to keep a storyboard reference in your appdelegate to push a viewcontroller. You can do it by calling self instead,

ProductDetailVC *aObjVC = [self.mainStoryBoard instantiateViewControllerWithIdentifier:@"ProductDetailVC"];
[self.navigationController pushViewController:aObjVC animated:YES];
Rukshan
  • 7,902
  • 6
  • 43
  • 61
  • I have tried with "self.storyboard" but even its not works. ProductDetailVC *aObjVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ProductDetailVC"]; [self.navigationController pushViewController:aObjVC animated:YES]; – Nirav Patel Jul 16 '17 at 17:34
  • 1
    check this, https://stackoverflow.com/questions/24020610/how-to-access-both-objective-c-and-swift-classes-from-same-storyboard – Rukshan Jul 16 '17 at 17:40
  • Thanks! Just able to resolve it by above link, Created another storyboard and put viewcontroller in new storyboard. And works perfect. but its not works in my old storyboard need to create newer. – Nirav Patel Jul 16 '17 at 17:52
0
  1. Double check the class_name "ProductDetailVC".
  2. Remove the class_name, and type again and press enter.
  3. then check the identifier.
  4. Module should not nil

enter image description here

    ProductDetailVC * productDetailVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ProductDetailVC"];

    [self.navigationController pushViewController:productDetailVC animated:TRUE];
junaidsidhu
  • 3,539
  • 1
  • 27
  • 49
  • Yes I have added already, Please check my question again i have added screenshot. – Nirav Patel Jul 16 '17 at 17:43
  • @NiravPatel whats your storyboard name ? – junaidsidhu Jul 16 '17 at 17:45
  • "Main" Default storyboard name. – Nirav Patel Jul 16 '17 at 17:46
  • Yes i tried that way as well but not works, just able to resolve it by creating new storyboard and created viewcontroller in that storyboard and after that its works. – Nirav Patel Jul 16 '17 at 17:54
  • @NiravPatel then your connections must be broken for some outlets – junaidsidhu Jul 16 '17 at 17:55
  • 1
    I think all proper, might be issue need to upgrade storyboard. I checked below link and there mentioned that i have create Main in old xcode and newer xcode i create swift class so need to upgrade storyboard. https://stackoverflow.com/questions/24020610/how-to-access-both-objective-c-and-swift-classes-from-same-storyboard – Nirav Patel Jul 16 '17 at 17:57