Storyboard doesn't contain a view controller with identifier - ios

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.

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)

In Xcode 7 - 13,
when you change storyboard IDs and you get errors like this,
just CLEAN your project (CMD+SHIFT+K)

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).
Sometimes people believe that the first one is the Storyboard ID and the second one the View Controller class name, so note the difference.

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:
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

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

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.

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).

For those with the same issue as #Ravi Bhanushali, here is a Swift 4 solution:
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)

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

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).

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

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">

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.

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....

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

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

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.

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.

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.
Rename/fix any wrong names which you find.
Save all changes.
Clean and build your project.
Everything should work fine now.
This is most often caused when you rename files from within Xcode.

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

XCODE DRAG N DROP PANE IS GONE!!!

Related

Can't change rootViewController in Appdelegate?

I design a soft Pin.
You can put 4 numbers twice and it will be your code. When you finished code assignment. The view will present segue (kind: Present Modally) to show another viewController.
Due to convenient, I would like to reset the View controller.
The Best way I found on the stack overflow is to reset rootViewController in the Appdelegate
Solution Here
When I follow the steps, I got an error below :
The Console shows :
Maybe the problem is the design in my storyboard
The upper one is original viewController
Can anyone figure out what's wrong with my code?
Thanks a lot!!!
The problem is from your Storyboard : you don't have a view controller with a StoryBoard ID EnterPinViewController.
Go to your Storyboard, select the controller and on side panel Utilities check the StoryBoard ID value.
Or change instantiateViewControllerWithIdentifier parameter with the one matching the Storyboard Identifier of your view controller.
Click on your controller in storyboard.
In right side panel go to identity Inspector (3rd button)
Set Storyboard ID to EnterPinViewController
You are all set to go further now!!

Using Storyboard Reference

How to use Storyboard reference to connect 2 storyboards? Is it possible to connect storyboard with xib file? I want to use it via Navigation Controller.
if you want to reference two storyboards in Xcode 7, in your initial storyboard select the view controllers you want to use in the second storyboard, in the task bar select "Editor" and then "Refactor to Storyboard", then you have to name the new storyboard and thats all, i don´t know if you can reference to an .xib file, notice that you can use the storyboard reference to call a view even in the same storyboard or even a view that is not connected to any other view, and in the reference you can specify which view you want to load (you do this in the identity inspector), or leave that space empty and the view loaded will be the initial view.
Better explained step by step:
If you want to create the new storyboard at the same time
select the views you want to move to the new storyboard
open the Editor's menu and select Refactor to Storyboard
Xcode will ask you the name you want to give to the new storyboard
and thats all
If you have already created the storyboard
Open the storyboard where you want to call the second storyboard
drag the Storyboard Reference that is located in the objects library
select the reference you added and open the identity inspector
in the identity inspector write the name of the storyboard that you want
to call (required) and the storyboardID of the view you want to load
(optional)
thats how you use storyboard references in Xcode 7, hope that is useful to you
You can load another storyboard simply like this your main storyboard..just replace the name of storyboard and viewcontroller
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"NewStoryboard" bundle: nil];
SomeViewController *someViewController = [storyboard instantiateViewControllerWithIdentifier:#"SomeViewController"];
[self presentViewController:someViewController animated:YES completion:nil];
or Swift
let storyboard = UIStoryboard(name: "NewStoryboard", bundle: nil)
let someViewController = storyboard.instantiateViewControllerWithIdentifier("SomeViewController") as! UIViewController
self.presentViewController(someViewController, animated: true, completion: nil)
Hi Friend this is really easy,
Just create a new Storyboard with file>newfile and get the new Storyboard from User Interface don't forget to name it properly ;)
Drag a Storyboard reference to your main story board and now connect it with button or navigation bar button or tab bar whatever (as per your requirement)and thats it...
Select Storyboard reference and go to Attribute Inspector you can see the dropdown of story board from that select your new Storyboard.
Create any new view controller in the empty Storyboard and make it initial view controller.
Run the code
This is how you do it my friend hope it helps :)
Tell me if you are not able to solve will update my answers with screen shots.

Storyboard doesn't contain a view controller with identifier ... when using multiple storyboard files

I used to have all my view controllers in the same storyboard, I decided that makes sense to split up the storyboards so I created a new storyboard file New File -> User Interface -> StoryBoard, cut all the controllers related with the user management (Login, register, password recover ...) and pasted them in the new file
Now when I call storyboard.instantiateViewControllerWithIdentifier("LoginViewController") it crashes with the following error:
'Storyboard (<UIStoryboard: 0x...>) doesn't contain a view
controller with identifier 'LoginViewController''
How can I solve that?
I think your problem is here, navigate to the Main.storyBoard after that click on your viewController which you want to initiate after that give it to the identifier here:
May be this will help you.
You have to create the new storyboard instance, and get the LoginViewController StoryboardId
//Here, create an instance of the second storyboard excluding the extension(.storyboard),
var storyBoard = UIStoryboard(name: "SecondStoryBoard", bundle: nil)
//Here instantiate view controller with the storyboard instance,
//Before that create a storyboardId for the corresponding view controller.
var loginVC = storyBoard.instantiateViewControllerWithIdentifier("loginViewController") as LoginViewController
//Here, the storyboard identifier is "loginViewController" which is created in the respective view controller's "Identity" inspector
Hope this helps, Happy Coding :)

Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?

I am using Xcode in a newly created app and when I run the project it does not show in the iOS Simulator and I get the following message:
Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?
I've Googled about it of course and everybody points out that this is happening because Xcode does not know yet which view controller is the initial one. But the weird thing is that I created the app as a page based (also tried single-view and tabbed app options) app and Xcode already had defined a Storyboard for it.
Also, when I go to the main interface option of the project the storyboard (named "Main" by Xcode itself) is set, and in the Storyboard, my view controller is set as the "Initial View Controller"
What is wrong?
Check Is Initial View Controller in the Attributes Inspector.
So this also happened to me too. I checked 50 times and my "Is Initial View Controller" was checked, believe me. It happened out of the blue. So how did I fix it?
Create a new Storyboard in your project, name it something like Main_iPhoneV2 (or iPadV2 depending on your original storyboard style)
Open the broken storyboard, click anywhere in the white area and press command-a, then command-c (select all and copy)
Open your new storyboard and press command-v to paste the same exact setup
Go to your project settings, change your "Main Interface" to the new Main_iPhoneV2 (If it's your iPad and you're writing a universal app, you'll have to edit the -Info.plist and look for the value "Main storyboard file base name (iPad)
Recompile, and stop pulling your hair out
First click on the View Controller in the right hand side Utilities bar. Next select the Attributes Inspector and make sure that under the View Controller section the 'Is Initial View Controller' checkbox is checked!
This warning is also reported if you have some code like:
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = myAwesomeRootViewController
window?.makeKeyAndVisible()
In this case, go to Target > General > Deployment Info and set Main Interface to empty, since you don't need a storyboard entry for your app:
I have experienced this with my Tab Bar Controller not appearing in the Simulator along with a black screen. I did the following in order for my app to appear in the Simulator.
Go to Main.storyboard.
Check the Is Initial View Controller under the Attributes inspector tab.
If you accidentally deleted that view controller, or otherwise made it not the default, then you’ll see the error “Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?” when your app launches, along with a plain black screen.
To fix the problem, open your Main.storyboard file and find whichever view controller you want to be shown when your app first runs. When it’s selected, go to the attributes inspector and check the box marked “Is Initial View Controller”. You should see a right-facing arrow appear to the left of that view controller, showing that it’s your storyboard’s entry point.
Using Interface Builder :
Check if 'Is initial view controller' is set. You can set it using below steps :
Select your view controller (which is to be appeared as initial screen).
Select Attribute inspector from Utilities window.
Select 'Is Initial View Controller' from View Controller section (if not).
If you have done this step and still getting error then uncheck and do it again.
Using programmatically :
Objective-C :
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"HomeViewController"]; // <storyboard id>
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
Swift :
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var objMainViewController: MainViewController = mainStoryboard.instantiateViewControllerWithIdentifier("MainController") as! MainViewController
self.window?.rootViewController = objMainViewController
self.window?.makeKeyAndVisible()
return true
Setup the window manually,
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (!application.keyWindow.rootViewController)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *myViewController= [storyboard instantiateViewControllerWithIdentifier:#"myViewController identifier"];
application.keyWindow.rootViewController = myViewController;
}
}
None of the above solved the issue for me. In my case it was not also setting the correct application scene manifest.
I had to change LoginScreen used to be Main
I get this error when I change the the storyboard file name "Main.storyboard" TO: "XXX.storyboard"
The solution for me was:
Product->Clean
CHANGE: Supporting Files -> info.plist -> Main storyboard file base name -> Main TO: XXX
Good Luck
Product "Clean" was the solution for me.
Apart from above correct answer, also make sure that you have set correct Main Interface in General.
1st option
if you want to set your custom storyboard instead of a default view controller.
Change this attribute from info.plist file
<key>UISceneStoryboardFile</key>
<string>Onboarding</string>
Onboarding would be your storyboard name
to open this right-click on info.plist file and open as a source code
2nd option
1- Click on your project
2- Select your project from the target section
3- Move to Deployment interface section
4- Change your storyboard section from Main Interface field
Please remember set your storyboard initial view controller
Projects created in Xcode 11 and above, simply changing the Main Interface file from the project settings won't be enough.
You have to manually edit the Info.plist file and set the storyboard name for the UISceneStoryboardFile as well.
If you added new storyboard then you have to check following points:
In your plist file check value of Main storyboard file base name (iPad) or (iPhone) should be matched with your storyboard file name (do not add extension .storyboard)
In storyboard there should be one view controller which set as Is initial view controller
Clean and build your project. :)
If you have been committing your code to source control regularly, this may save you the hassle of creating a new Storyboard and possibly introducing more problems...
I was able to solve this by comparing the Git source code of the version that worked against the broken one. The diff showed that the first line should contain the Id of the initial view controller, in my case, initialViewController="Q7U-eo-vxw". I searched through the source code to be sure that the id existed. All I had to do was put it back and everything worked again!
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="Q7U-eo-vxw">
<dependencies>
<deployment defaultVersion="1296" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
<scenes>
Here are some steps that can help you troubleshoot:
Right click the failing Storyboard and use Source Control > Commit... to preserve your changes since the last commit.
Try right clicking your failing Storyboard and use "Open As > Source Code" to view the XML of the storyboard.
In the document element, look for the attribute named "initialViewController". If it is missing, don't worry, we'll fix that. If it is there, double click the id that is assigned to it, command-c to copy it, command-f command-v to search for it deeper in the document. This is the identifier of the controller that should provide the initial view. If it is not defined in the document then that is a problem - you should remove it from the document tag, in my case initialViewController="Q7U-eo-vxw".
Go to Xcode menu item called View and choose Version Editor > Show Comparison View
This shows your local version on the left and the historical version on the right. Click on the date beneath the historical version to get a list of the commits for this story board. Choose one that you know worked and compare the document element. What is the id of the *initialViewController? Is it different? If so, try editing it back in by hand and running.
Check if you have the window var in the AppDelegate.
var window: UIWindow?
And also check the storyboard of your Info.plist file.
<key>UIMainStoryboardFile</key>
<string>Main</string>
Programmatically setting the rootViewController in the AppDelegate is not going to fix the warning. You should choose whether to let to the storyboard set the view controller or do it programmatically.
If you have scene delegate you have to check in info.plist
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Login</string>
</dict>
</array>
</dict>
</dict>
I'm here loading my storyboard called Login.storyboard
plist
If you've created a new Storyboard with a name other than "Main" there will be some problems, but it's easy to adjust...
So after you've created a new Storyboard with the desired name and you want to use it as the main story, do the following:
Check box 'Is Initial View Controller' inside Attributes Inspector:
Choose desired storyboard as 'Main Interface' for your target:
Open project Info.plist and find a property 'Storyboard Name' where you should type your desired Storyboard name as value
If you are not using storyboard
Open info.plist
In the info.plist file delete the following feature
Information Property List -> Scene configuration -> Application Session Role -> Item 0 -> StoryBoard Name
What worked for me in XCode 14.0.1 was, apart from setting initial view controller, to update in Build Settings: "UIKIT Main Storyboard File Base Name" to new the name of new storyboard
For future readers:- iOS 13, Swift 5
I set initial view controller programmatically from SceneDelegate, I got this as warning and the view controller is set perfectly. So I delete Storyboard Name from Info.plist and the warning is gone forever.
Info.plist > Application Scene Manifest > Scene Configuration > Application Session Role > Storyboard Name > Delete this one

How do I give an "identifier" to a view controller within my storyboard?

The instantiateViewControllerWithIdentifier: method requires that the view controller I pass have an identifier. I went to my storyboard and clicked on my view controller, but I see no option to set the identifier. Where exactly do I find this option?
As the Image suggests! Hope it helps!
Then to use it you call:
[self.storyboard instantiateViewControllerWithIdentifier:#"YourViewControllerID"];
Updated for XCode 8 and Swift 3.
instantiateViewControllerWithIdentifier is now instantiateViewController(withIdentifier:).
Setting the storyboard ID:
In the identity inspector there is a field Storyboard ID. You could enter the class name here and then use this identifier in instantiateViewControllerWithIdentifier:.

Resources