Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Storyboard doesn't contain a view controller with identifier' only on Device

I have this storyboard :

enter image description here

With this ViewController :

enter image description here

I have this code to instanciate my VC :

let VC = UIStoryboard(name: "Main_iPhone", bundle: nil).instantiateViewControllerWithIdentifier("POIListViewController")

When i'm running on simulator, everything works thine.

But when i launch on real device, i have this exception :

2016-07-12 10:56:19.073 App-Ely[1935:562264] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x185481b0>) doesn't contain a view controller with identifier 'POIListViewController''
*** First throw call stack:
(0x2a23b5f7 0x37aadc77 0x2dc36f25 0x182b8c 0x182dd0 0x12d99f 0x2a1f3f15 0x2a14ee4d 0x2ae83ec1 0x13e0d5 0x168a2d 0x2d7f9607 0x2d8ab0a7 0x2d75d1f1 0x2d6d8eff 0x2a202015 0x2a1ff6f9 0x2a1ffafb 0x2a14cb31 0x2a14c943 0x3152c051 0x2d7426f1 0x16fce3 0x38049aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException

EDIT :

I have my storyboard correctly loaded :

    let storyboard = UIStoryboard(name: "Main_iPhone", bundle: nil)
    // 'storyboardName' contains "Main_iPhone"
    let storyboardName : String = storyboard.valueForKey("name") as! String
    let VC = storyboard.instantiateViewControllerWithIdentifier("POIListViewController")
like image 575
Kevin ABRIOUX Avatar asked Jul 12 '16 09:07

Kevin ABRIOUX


People also ask

How do I set the identifier for view controller in storyboard?

In the Storyboard, select the view controller that you want to instantiate in code. Make sure the yellow circle is highlighted, and click on the Identity Inspector. Set the custom class as well as the field called "Storyboard ID". You can use the class name as the Storyboard ID.

How do I embed a view controller in navigation controller storyboard?

In your storyboard, select the initial view controller in your hierarchy. With this view controller selected, choose the menu item Editor -> Embed In -> Navigation Controller .

How do I add SwiftUI view to storyboard?

Step 1: Inside your storyboard file click on the + button and drag and drop a Hosting View Controller. This View Controller is capable of hosting a SwiftUI view.


3 Answers

let storyboard = UIStoryboard(name: "Main_iPhone", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("POIListViewController") as! UIViewController

EDIT

Just CLEAN your project (CMD+SHIFT+K) as you have change the storyboard name I think.

like image 95
Bhadresh Mulsaniya Avatar answered Sep 21 '22 13:09

Bhadresh Mulsaniya


I had a similar problem (except it wasn't only on device).

None of the previous suggestions in this thread worked for me. What worked was going to the Identity Inspector (in right hand Utilities Pane), and making sure the Storyboard ID field was also populated with the View Controller name (same name as the Class field above it).

like image 24
Gsp Avatar answered Sep 22 '22 13:09

Gsp


Close your project and open it again. If you noticed the identifier is gone, then it must be a problem of auto-saving. Simply save your storyboard file after putting your new identifier. and Clean-Build-Run.

like image 30
Kyle KIM Avatar answered Sep 20 '22 13:09

Kyle KIM