Could not find a storyboard named 'MainStoryBoard' in bundle NSBundle
Asked Answered
P

27

46

I have started a new app a few days ago and began working with the simulator to test it. I started as an empty project and manually added the storyboard. The simulator builds and runs my app just fine but when I try to build to my iPhone I get the messsage 'Could not find a storyboard named 'MainStoryBoard' in bundle NSBundle'.

Google turned up nothing and this question suggested I checked my target for the storyboard, but everything is in place. Even so, if something wouldn't be in place, the simulator wouldn't run either.

Can anyone point me in the right direction?

Pruritus answered 1/1, 2012 at 18:35 Comment(1)
Check Your build phases to see if your storyboard is a copybundleresourceHeadstall
P
35

The simulator is not case sensitive, but the device is. If your storyboard is called MainStoryboard, not MainStoryBoard, this will cause your problem.

Petrol answered 8/1, 2012 at 7:16 Comment(1)
above solution is 100% correct. But if you are using more than one storyboard for your app, then better leave storyboard name as blank in .plist.....hope i am helpful.Linsk
W
77

I had my app working normally on the iPhone Simulator but strangely Xcode stopped responding and i had to Force Quit Xcode. When I restarted Xcode i encountered "Could not find a storyboard named MainStoryboard....",

I have fixed this issue by following below steps:

  1. Renaming "MainStoryboard.storyboard" to "MainStoryboard_1.storyboard"
  2. Open file "$your_app$-Info.plist" located in "Supporting Files" folder. Edit "Main storyboard file base name" to "MainStoryboard_1.storyboard".
  3. Rerun the app, and it worked for me.
  4. I renamed my storyboard file back to its original "MainStoryboard.storyboard".
  5. Edited the .plist file back to its original.
  6. Rerun the app, and it worked for me.

For some reason the file "MainStoryboard.storyboard" was not recognised after force quitting Xcode and following above steps made the app recognise the file back again.

Hope this solution helps..

Wornout answered 21/2, 2012 at 10:46 Comment(6)
this worked for me, thanks for keeping my hair from falling out.Atchley
I change the .plist file, saved, and changed it back, which made no difference for me. Then I renamed the .storyboard file and renamed it back and it worked from then.Defray
worked for me too, thanks! just an FYI, I never shut down XCode but followed the steps and it worked (so you don't need to open and close XCode)Genny
I also find it helpful to delete Derived Data as well.Gen
This helped me finally get past my IOS for Dummies chapter where their tic tac toe example would not start due to missing story board.Belinda
This sort of answer is what makes StackOverflow worth every penny we pay for it. Best answers for cryptic Xcode BS.Heterozygous
P
35

The simulator is not case sensitive, but the device is. If your storyboard is called MainStoryboard, not MainStoryBoard, this will cause your problem.

Petrol answered 8/1, 2012 at 7:16 Comment(1)
above solution is 100% correct. But if you are using more than one storyboard for your app, then better leave storyboard name as blank in .plist.....hope i am helpful.Linsk
N
24

Just want to mention scenario I encountered. I don't know how, but storyboard disconnected from the target although it still was part of the project. To fix this I opened storyboard, selected "File Inspector"(leftmost icon on the right panel) and check the project under "Target membership". Hope it helps someone.

Nosh answered 1/7, 2014 at 13:56 Comment(1)
It amazes me how things become unchecked radically! Thanks! This solved my issue!Galahad
M
11

The problem occurs when you deselect "Use Base Internationalization" and run simulator in different locale rather than your specific localization.

For example, you specify a zh-CN localization in project setting but run simulator under en-US.

Mutate answered 18/3, 2014 at 5:10 Comment(1)
Xcode 11 is calling this "Localization native development region" I think, but changing it makes it work.Rf
T
7

Tried all solutions mentioned above but didn’t worked.

After thorough research found the culprit:

Copy Bundle Resource was missing from TARGETS -> Build Phases

This got accidentally removed while removing Cocoapods.

Below are steps to fix this :

  1. Go to TARGETS of your project
  2. Click on plus (+) button present on top left corner
  3. Select New Copy Bundle Resources from drop down
  4. Now, add you Storyboard files (Main, Launchscreen etc). Also add Assets folder. You can add these files by clicking on plus (+) button present in bottom

screenshot

  1. Delete the derived data content
  2. Delete the app from Simulator/Device and run again
Tradespeople answered 16/2, 2017 at 11:0 Comment(0)
O
4

I thought you may have deleted the storyboard and decided to use a .xib file on initial app launch. In this scenario, Xcode would try to find a nonexistent storyboard.

For this case, click on the Project > Info > Custom iOS Target Properties and delete this key value pair: Main storyboard file base name

Outport answered 22/12, 2014 at 6:44 Comment(1)
Actually, the value for UIStoryboard storyboardWithName method is exactly there which is Main. In conclusion: [UIStoryboard storyboardWithName:@"Main" bundle:nil]Clarkin
A
3

A simple Clean corrected the error for me.

Arce answered 28/5, 2015 at 21:30 Comment(2)
:) fantastic. Corrected too me.Eustoliaeutectic
Worked for me as wellMerrell
U
3

If you are using for navigation on source code, try to use below code

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

Often people will enter "Main.storyboard" for the name, since that is literally the name of the file, but for the purposes of Obj-C coding, "X.storyboard" has the name "X", so in this case, @"Main".

Unless answered 19/11, 2015 at 6:7 Comment(1)
This was my case, I first tried the name as "Main.storyboard" because this is what I saw in the File inspector > Nama, after I've selected the storyboard. But it seem we have to use the name found in Info.plist > Main storyboard file base name, which is just "Main". So for me, this worked: let myStoryboard = UIStoryboard(name: "Main", bundle: nil)Tophus
B
3

This helped me (Swift 2.1, Xcode 7.2) for an app with a tab bar

    let storyboard: UIStoryboard = UIStoryboard(name:"Main",bundle: NSBundle(forClass: self.dynamicType))
    let tabController = storyboard.instantiateViewControllerWithIdentifier("MyTabBarIdentifier") as! UITabBarController

I had the Main.storyboard with the correct target membership, copy bundle resources, cleaned build folder, etc (most of the answers were pointing to this).

Bushing answered 28/1, 2016 at 16:11 Comment(1)
this helped me - I posted another answer to show how it helped. thanks!Fragmentation
F
3

Nitin Alabur's answer helped me, but indirectly. Posting another answer to clarify:

I am building a dynamic framework with a storyboard inside it, and in the test app I am building to test the framework, I was getting this error.

My code looked like this:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:nil];

I was ignoring the NSBundle stuff because, hey, I don't know what the heck a bundle is. Turns out it's important for this use case, where the storyboard will exist outside of the application's "bundle" (it's in my framework's bundle instead). This code will tell iOS to find the storyboard within the bundle that the current class exists in (which for me, is the bundle that contains my framework):

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:[NSBundle bundleForClass:[self class]]];
Fragmentation answered 14/6, 2016 at 19:57 Comment(0)
W
3

Update: Swift 5 and iOS 13:

  1. Create a Single View Application.
  2. Delete Main.storyboard (right-click and delete).
  3. Delete Storyboard Name from the default scene configuration in the Info.plist file: enter image description here
  4. Open SceneDelegate.swift and change func scene from:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
    guard let _ = (scene as? UIWindowScene) else { return }
}

to

 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).x

    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = ViewController()
        self.window = window
        window.makeKeyAndVisible()
    }
}

Now you are good to go :)

Whitton answered 22/10, 2019 at 12:42 Comment(0)
G
2

Go to your project, select your target and pull down from the menus to re-select your storyboards.

Also, you can update your plist, I found that changing one did not change the other.

Guyon answered 1/11, 2012 at 14:13 Comment(0)
E
2

You just need to check your configuration file (.plist) under Supporting files folder

Check the name of your default storyboard.

Edyth answered 20/11, 2015 at 15:54 Comment(0)
C
2

I also had same issue, what caused this type of exception is I had written "Main.storyboard" instead of "Main". We don't have to specify .storyboard extension.

Chesterchesterfield answered 25/4, 2017 at 5:29 Comment(0)
D
1

I had similar problem and I was getting the following error.

exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'MainStoryboard_iPhone' in bundle NSBundle

I fixed it by updating the plist file. Simply goto Edit->Find->Find in Workspace and search for "story". Now update the appropriate name for the story board.

Dinnerware answered 19/3, 2012 at 20:59 Comment(0)
R
1

To prevent this from happening I have had to change the way I work with storyboard files. After editing the storyboard save the file then exit XCode. This seems to prevent the problem from occurring.

Rancid answered 28/2, 2013 at 21:23 Comment(0)
O
1

I had this problem when I accidentally opened a project with a second install of Xcode. It broke my project files permanently (which is understandable).

Occlusion answered 7/3, 2013 at 15:22 Comment(0)
D
1

This problem happened for me when i was calling storyboard in code.The reason was i used different 'word' for storyboard.I solved it like this

Go to Targets ->info , select info,copy name of storyboard and paste it to where you are calling storyboard.

At least give a try….

Dunkin answered 13/1, 2014 at 7:34 Comment(0)
C
1

This happened to me when I had a previous app with the same name installed on the simulator.

I have removed the previous app, re-selected the Storyboard on the "Deployment Info", re-run the app, and everything worked fine.

Convery answered 16/8, 2014 at 12:14 Comment(0)
W
1

There are 2 possibilities,

  1. Make sure your Storyboard is added to your target.

Select Storyboard > Go to file inspector (first right tab) > Check Target Membership

enter image description here

  1. Initialize storyboard with proper bundle.

    • If storyboard is in same target you are working on then use bundle = nil
    • If storyboard is in different target than you are working on, then try following code to initialize bundle and storyboard.

      let bundle = Bundle(for: MyClass.self)
      let storyboard = UIStoryboard(name: "Main", bundle: bundle)
      
Westbrooks answered 4/11, 2017 at 9:49 Comment(0)
G
0

If you recently reset your iOS sim to default settings, it's also useful to check locale settings in its Preferences. I'm working on the app with Russian as the only locale and after sim reset the xCode stopped to start the app because the sim locale was set to English.

Grey answered 2/12, 2012 at 18:29 Comment(0)
F
0

I had this error on the device when I added about 150 fonts to UIAppFonts.
After I reduced their count to about 100, it went away.

Farmhouse answered 11/1, 2013 at 4:16 Comment(0)
E
0

I had this problem in a project that had storyboards with and without ~iPad or ~iPhone suffixes, like MainStoryboard.storyboard and MainStoryboard~iPad.storyboard.

The problem was that MainStoryboard.storyboard was overwriting MainStoryboard~iPad.storyboard when it got compiled into the build directory. If the files were compiled in the opposite order, both would be preserved without issue. I have no idea why this happens.

To get around this, you can stop using ~iPad/iPhone suffixes or make sure the files are in the right order in the Copy Bundle Resources phase.

(Using XCode6.2beta2)

Evincive answered 23/3, 2015 at 22:0 Comment(0)
E
0

A very silly one but I had "MainStoryboard.storyboard" in the "Main storyboard file base name (iPad)" entry of my my .plist instead of just "MainStoryboard".

Euterpe answered 30/3, 2015 at 14:19 Comment(0)
S
0

The solution for me was, that I just needed to add the MainStoryboard to the Bundle Resources. After that, it works fine.

Project -> Build Phases -> Copy Bundle Resources -> click on the + button and add your file.

Sanction answered 29/9, 2015 at 16:16 Comment(0)
L
0

Go to your info.plist on Build Phases > Copy Bundle Resources and add your storyboard using the icon "+"

Lagrange answered 15/10, 2015 at 18:46 Comment(0)
O
0

In my case, it was a storyboard inside a framework for a Mac application. I was using:

let storyboard = NSStoryboard(name: "StoryboardName", bundle: nil)

and needed to use the framework's bundle identifier to get the correct bundle:

let storyboard = NSStoryboard(name: "StoryboardName",
                            bundle: Bundle(identifier: "com.company.FrameworkName"))
Orlina answered 23/10, 2017 at 1:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.