199

I keep getting the following error:

Storyboard (<UIStoryboard: 0x7ebdd20>) doesn't contain a view controller with identifier 'drivingDetails'

This is the code:

- (void)tableView:(UITableView *)tableView 
        didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

   UIViewController *controller =  [self.storyboard instantiateViewControllerWithIdentifier:@"drivingDetails"];
   controller.title = [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"name"];
   [self.navigationController pushViewController:controller animated:YES];
}

I have already set the identifier on the UIStoryboard but I'm still getting this error.

enter image description here


pkamb
  • 33,281
  • 23
  • 160
  • 191
Mat
  • 6,236
  • 9
  • 42
  • 55
  • 4
    Looks like you set the identifier of a segue, not a view controller. Which view controller in that picture are you trying to present? And why aren't you just using a segue? – Firoze Lafeer Nov 28 '11 at 12:39
  • Up to Driving view controller works well.... than when I try to present TableViewController I get the error...... how would you do it? – Mat Nov 28 '11 at 12:46
  • Go to Storyboard, remove that Storyboard ID, and add again. You sometimes need to clean build folder and derived data – onmyway133 Feb 20 '19 at 13:37

21 Answers21

255

Just for future reference:

I'm developing on iOS 6 using Storyboards.

I was having the same issue, but I could not find the "Identifier" field in the inspector. Instead, just set the field named "Storyboard ID" to what you would name the Identifier. This field can be found under the "Show the Identity inspector" tab in the inspector.

[Note - comments below indicate that some people have found that they need to (also?) set the field "Restoration ID" just below the Storyboard ID in the inspector. Clicking on "Use Storyboard ID" does not seem to be enough.]

There's an image below for reference: (in this instance I've named my identifier the same as my class) enter image description here

Andy Weinstein
  • 2,639
  • 3
  • 21
  • 32
khaliq
  • 3,125
  • 4
  • 17
  • 23
201

In Xcode 7 - 13,

when you change storyboard IDs and you get errors like this,

just CLEAN your project (CMD+SHIFT+K)

Ted
  • 22,696
  • 11
  • 95
  • 109
  • 15
    Why do I always forget to do this? It fixes the craziest problems. Thanks, Ted, for reminding me! – AppDever Oct 16 '15 at 01:28
  • 2
    This issue occurred in XCode 7.2 when pulling from a repo in which a VC in the storyboard had been assigned an identifier. Cleaning the project seemed to resolve the issue. – Ed Holloway-George Jan 22 '16 at 19:16
  • 2
    I thought I was losing my mind...a simple segue wasn't working, this did the trick. – dokun1 Apr 08 '16 at 09:37
  • 2
    Yes Its working !!!! some time Cleaning the xcode project will remove unwanted reference to project – kiran May 27 '16 at 09:29
  • 4
    I'm coming from Android Studio and Android development. This is crazy how many hacks I have to use in XCode and Swift. I really have to cry. Seriously. – ktamas May 14 '18 at 18:09
  • 1
    I had similar but worse variation of this in Xcode 10, where I had same storyboard open in two tabs. Making changes in one and cleaning didn't help. When I noticed that I had two tabs open with the same storyboard and closed one I saw that no changes persisted to the other tab. So when I wrote Storyboard ID again in that tab things started to work. – Stanislav Goryachev Mar 13 '19 at 10:11
  • this is so sad.. cleaning and rebuilding a legacy in-production app takes me 15 minutes... – fusion Jul 30 '21 at 13:43
59
let storyboard = UIStoryboard(name: "StoryboardFileName", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "StoryboardID")
self.present(controller, animated: true, completion: nil)

Note:

  • "StoryboardFileName" is the filename of the Storyboard and not the ID of the storyboard!
  • "StoryboardID" is the ID you have manually set in the identity inspector for that storyboard (see screenshot below).

Storyboard ID

Sometimes people believe that the first one is the Storyboard ID and the second one the View Controller class name, so note the difference.

Rafael
  • 7,002
  • 5
  • 43
  • 52
  • 1
    This!! My man you just solved my 18 hour mystery. Thank you for the concise explanation. – FevtheDev Aug 26 '19 at 12:52
  • 2
    Jesus christ! Thanks for this! ```.instantiateViewController(withIdentifier: "StoryboardID")``` should be renamed to ```.instantiateStoryboard(withIdentifier: "StoryboardID")``` Or just something simpler ```UIStoryboard(name: "StoryboardFileName", bundle: nil).init()``` – roosevelt Feb 22 '20 at 00:25
  • Does it make sense that after setting the name in "Storyboard ID" that I also needed to check the "Use Storyboard ID" checkbox for this to work? – mamills Dec 08 '22 at 22:58
44

Fixed! Not only the identifier in the segue must be set, in my case DrivingDetails, but also the identifier in my tableViewController must be set as DrivingDetails...check my picture:

enter image description here

I also removed the navigation view controller so now the 2 table view controllers are connected directly with a "push" animation.

*****EDIT for XCODE 7.0*****

you have to set the storyboardId(in this case the viewController is embedded in a Navigation controller:

let lastMinVc  = mainStoryBoard.instantiateViewControllerWithIdentifier("lastMinuteNavController") as! UINavigationController

enter image description here

Mat
  • 6,236
  • 9
  • 42
  • 55
  • 2
    I am running into a similar problem to this question but when i go to the attributes inspector i don't see 2 fields like in your screen shot only a Title field, no identifier field – Anon957 May 11 '13 at 02:34
  • have you looked at the answer above? I think is more updated. Thanks – Mat May 11 '13 at 19:21
  • 1
    The identifier for the segue has nothing to do with this. Only the Storyboard ID for the view controller needs to be set in the storyboard. – Jawwad Sep 21 '13 at 15:47
  • Possibly related. In iOS7 `[storyboard instantiateViewControllerWithIdentifier]` is NOT instantiating the views from Interface Builder inside the view controller; but in iOS6 it did – William Entriken Sep 22 '13 at 03:38
18

Identity located in Identity Inspector tab named Storyboard ID for Xcode 6.3.2 and checked Use Storyboard ID option. enter image description here

SerkanHocam
  • 536
  • 6
  • 18
  • This was the problem all along, this worked in both places I was having problems. Its not just the Storyboard ID value being set, *you need to* check the 'Use Storyboard ID' – Tyler Hackbart Feb 24 '18 at 16:51
  • "Use Storyboard ID" was the vital piece missing for me. Thank you. – Marcy Sep 21 '18 at 01:14
9

Just had this issue after adding a new VC to the storyboard but only on the device, not on the simulator. Turns out it was due to having multiple storyboard localizations - the VC was only added to the primary one. I tried removing the other localizations (one of which is the one my iPhone uses) but still had the error. In the end I had to recreate the other localizations with the new VC in each of them.

Hari Honor
  • 8,677
  • 8
  • 51
  • 54
6

Compiler shows following error :

Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Storyboard (<UIStoryboard: 0x7fedf2d5c9a0>) doesn't contain a 
ViewController with identifier 'SBAddEmployeeVC''

Here the object of the storyboard created is not the main storyboard which contains our ViewControllers. As storyboard file on which we work is named as Main.storyboard. So we need to have reference of object of the Main.storyboard.

Use following code for that :

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];

Here storyboardWithName is the name of the storyboard file we are working with and bundle specifies the bundle in which our storyboard is (i.e. mainBundle).

Ravi Bhanushali
  • 145
  • 2
  • 9
5

For those with the same issue as @Ravi Bhanushali, here is a Swift 4 solution:

let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)

confitz20
  • 61
  • 2
  • 3
4

I found it ... click on the view controller in storyboard, click the third icon from left on the vc attributes inspectors - the one where you set the call name on that scereen it says 'identity' - mine was hidden , i had to click on the word identity it then shows storyboardID - add the identifier from the code, done

Jon
  • 555
  • 5
  • 5
4

Modifying "Storyboard ID" in the identity inspector (the 3rd icon to the left) should work.

If not and you're sure there's no typo, try cleaning up the project ("Product"->"Clean", or simply command + shift + K).

aychen0110
  • 301
  • 2
  • 5
1

A few of my view controllers were missing the storyboardIdentifier attribute.

Before:

<viewController
    id="pka-il-u5E"
    customClass="YourViewControllerName"
    customModule="ModuleName"
    customModuleProvider="target"
    sceneMemberID="viewController">

After:

<viewController
    storyboardIdentifier="YourViewControllerName"   <----
    id="pka-il-u5E"
    customClass="YourViewControllerName"
    customModule="ModuleName"
    customModuleProvider="target"
    sceneMemberID="viewController">
Andrew
  • 3,733
  • 1
  • 35
  • 36
1

I was facing the same issue. I had given the identifier but the compiler was giving the issue, so I made the new controller and gave that controller a new ID and added it and it's working perfectly! I have added pods as well but don't know why the error was coming but now its gone! Plus also try to clean your project by pressing CMD+SHIFT+K keys. Lemme know if it worked.

arturovm
  • 1,215
  • 2
  • 12
  • 28
1

While entering the identifier u have not selected proper view controller, just check once if done repeat the procedure once more.

iamsult
  • 1,581
  • 1
  • 15
  • 21
  • which view controller should I select? sorry,i'm confused. – Mat Nov 28 '11 at 12:13
  • TableViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"drivingDetails"]; controller.title = [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"name"]; [self.navigationController pushViewController:controller animated:YES]; like this? – Mat Nov 28 '11 at 12:13
  • As per the image TableViewController should be selected as u are doing to display details in that controller. – iamsult Nov 28 '11 at 12:18
  • Step by step explanation of story board given http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1 – iamsult Nov 28 '11 at 12:22
  • can u paste the complete storyboard view. – iamsult Nov 28 '11 at 13:10
  • 1
    Just a little note your segue identifier and view controller identifier are different. I just wanted to highlight that incase there was some confusion since you are using the same name for both. Your segue identifier should be for use in prepareForSegue and your view controller identifier is for loading views from your storyboard directly. http://www.scott-sherwood.com/?p=219 – Scott Sherwood Dec 07 '11 at 00:51
0

I got same error and I could fix this by changing the following changes in my project. I have mentioned my class name in the inspector panel then the problem is solved. Goto->right panel there Identity Inspector In the custom class section

class:your class name(ViewController)

In the Identity section storyboard ID:your storyboard ID(viewController Name)

After this click on Use storyboard ID option over there.That's it the problem is finished. I hope it will help you....

Narasimha Nallamsetty
  • 1,215
  • 14
  • 16
0

Use your identifier(@"drivingDetails") as Storyboard ID.

Priyam
  • 69
  • 1
  • 3
0

I tried all of the above solutions and none worked.

What I did was:

  • Project clean
  • Delete derived data
  • Restart Xcode
  • Re-enter the StoryboardID shown in previous answers (inside IB).

And then it worked. The shocking thing was that I had entered the Storyboar ID in interface builder and it got removed/deleted after opening Xcode again.

Hope this helps someone.

Darkwonder
  • 1,149
  • 1
  • 13
  • 26
0

it is very simple select the respective view controller in the main story board and check the storyboardID if its present use it in the identidier of give a name and use it.

here my firstone is the storyboardID let vc = self.storyboard?.instantiateViewController(withIdentifier: "firstone") as! tabBarViewController

Saba Zehra
  • 63
  • 1
  • 10
0

Cleaning all things and closing Xcode doesn't solved the issue for me.

I had to delete the viewController and create a new one with new identifier.

user3722523
  • 1,740
  • 2
  • 15
  • 27
0

Note: If you use cocoapods in your project, then first run pod deintegrate and rm Podfile.lock

Then open your project folder in any third party code editor like VSCode and do a global search for the ViewController name throwing the error.

  1. Rename/fix any wrong names which you find.
  2. Save all changes.
  3. Clean and build your project.

Everything should work fine now.

This is most often caused when you rename files from within Xcode.

Arjun Shukla
  • 337
  • 7
  • 10
0

check your language, may be the (base) have your controller, but may be specific storyboard does not have it

famfamfam
  • 396
  • 3
  • 8
  • 31
-3

XCODE DRAG N DROP PANE IS GONE!!!

enter image description here enter image description here

Mr Heelis
  • 2,370
  • 4
  • 24
  • 34