ChatGPT解决这个技术问题 Extra ChatGPT

Could not find a storyboard named 'Main' in bundle

I'm getting a strange error: 'Could not find a storyboard named 'Main' in bundle NSBundle' when trying to run my app on a real iOS device.

I have the file in my directory, and it works fine in the simulator. However, in the Copy Bundle Resources section, the file Main.storyboard is red.

I've tried removing it and adding it again, restarting Xcode, cleaning build, etc. with no avail. This is the warning I get in Xcode:

/Users/ajay/Documents/avx/avx/Base.lproj/Main.storyboard: Internationalization of /Users/ajay/Documents/avx/avx/Base.lproj/Main.storyboard is not available when compiling for targets before iOS 6.0
I described how to solve the problem inside this post: stackoverflow.com/a/21098195/1141395
This issue mainly happens because of corrupt app installation. The solution is to clean and build the project. Also remove the existing app from device/simulator and run again.
Xcode 11 users, scroll down to the stackoverflow.com/a/58452686 , possibly it's exactly your case.

F
Fattie

https://i.stack.imgur.com/M90iH.png

https://i.stack.imgur.com/65P0S.png

For 2021...

You must also edit UIApplicationSceneManifest. See the more recent answers below.


Thanks, but this just made my app launch with a black screen. No crashes though.
Make sure to have these two lines in your - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions...: (1) self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; (2) self.window.backgroundColor = [UIColor whiteColor];
@ Carpetfizz Add '[self.window makeKeyAndVisible];' to your AppDelegate.
"app launch with a black screen", nobody has any idea for this?
@Umitk set the background to white (view.backgroundColor = .white) or any other color you like
P
Parth Tamane

For anyone facing this issue on Xcode 11, here's how you fix it if you face this issue when doing storyboard less project setup

(Adding some parts that ricardopereira missed)

1) First, delete the Main.storyboard file

2) Next, go to PROJECT_NAME -> GENERAL

In main interface drop-down, delete the text Main

https://i.stack.imgur.com/PJwOw.png

3) Now go to info.plist and delete Storyboard Name

https://i.stack.imgur.com/Xe2LY.png

4) Finally, modify scene(_:willConnectTo:options) code in the file SceneDelegate.swift (Yes! It's not in App Delegate anymore.)

var window: UIWindow?


    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 windowScene = (scene as? UIWindowScene) else { return }
        window = UIWindow(frame: windowScene.coordinateSpace.bounds)
        window?.windowScene = windowScene
        window?.rootViewController = ViewController()
        window?.makeKeyAndVisible()
    }

You can also refer to this video instead: https://www.youtube.com/watch?v=Htn4h51BQsk


Your answer is almost correct just there is a little change in scene function: guard let _ = (scene as? UIWindowScene) else { return } let viewController = ViewController() if let windowScene = scene as? UIWindowScene { self.window = UIWindow(windowScene: windowScene) self.window?.rootViewController = viewController self.window?.makeKeyAndVisible() }
To add some emphasis, the info.plist entry is not just the usual main storyboard entry but ALSO the one in the application scene manifest which is new for iOS 13. I had to read through twice before I realized.
This is the right way of doing things now! ^^ Apple kept changing things.
If you are a Xamarin dev, I found this to be very helpful: talkwithangel.com/…
J
JAL

You may check the target membership of the storyboard. May be there is where the problem is:

It should be looking like this:

https://i.stack.imgur.com/3i4TU.png


I had the same issue and at first I thought I wasn't copying the right resources to the target, but fixing target membership fixed the issue.
Thanks, worked! I did Clean, Rename File, Update Plist with no joy. It's always the most obvious that gets you.
Hi, I'm having the same issue but the target membership window is not showing, Xcode 7. Please help
For some reason, my target wasn't selected.. Thanks for this answer.. Solved!!
S
Shubham

An update for applications created for iOS 13.0 and above. (Xcode 11)

If you get the error "Could not find a storyboard named 'Main' in bundle even after changing the "Main storyboard File base name" in the info.plist and "Main Interface" under Deployment in Target.

Then you have to change another entry in the info.plist file.

Open the info.plist file. Expand "Application Scene Manifest". Expand "Scene Configuration". Expand the item 0 under "Application Sessions Role" and then change the storyboard name there.

https://i.stack.imgur.com/vNe7D.png

And your application will start working.


This is absolutely the right answer. It's apparently no longer enough to set the main storyboard from the General > Main Interface dropdown.
Thanks for this. Deleting the "Application Scene Manifest" key (along with all of its sub-keys) resolved the problem for me.
I literately don't know what happened but this is works
You saved my life :)
Thanks this is worked for me. if view is setup programmatically, you can just set the value to "LaunchScreen".
r
ricardopereira

In a project that uses UIScene in iOS 13 and Xcode 11, you need to remove the UISceneStoryboardFile key from the .plist.

Xcode 11:

https://i.stack.imgur.com/WtAmm.png

Changing directly from the file:

https://i.stack.imgur.com/AHmQB.png


u
user1021430

I deleted the app from my phone, did Product-->Clean, and loaded it again. That's all it took for me.


for every execution if deletes then only its executing me ...please help me in xcode 10.1
k
kraftydevil

I got this error, however, it was my intention to remove storyboards completely.

Removing the 'Main Storyboard file base name' key from my plist cured the error.


R
Randika Vishman

Could not find a storyboard named 'Main' in bundle

Reason I could think of:

As far as my iOS knowledge concluded me, this was just happened because the XCode was unable to find the reference to the Main.storyboard file within my project directory to copy it into the App.

Resolution:

Selected the Main.storyboard file and tried to delete, and from the dialog that pops up as follows: Clicked "Remove Reference" button. Then, from the actual place where I could find the Main.storyboard file within the project directory, dragged, and dropped to the XCode, and again from the dialog that pops up as follows: I choosed, "Create folder references" (because that's one thing I intended to do because I've changed my project's file and folder structure). But most of the times choosing "Create groups" also might work. And clicked on "Finish" button. My Storyboard files were already within as shown in the screenshot already within a Base.lproj directory as follows: Note: One important thing to remind here at this step is, don't forget to tick it ON the checkbox "Add to targets" to your app. Clean the Product, re-build, and if it is successful, most of the time try running it will be successful.

Hope this might be helpful to somebody else out there! I tried this on XCode 7.3.1 and on iOS Sim 9.3 and iPhone 6S!


Please help this am also facing this issue after installing the os10.14.1 and xc0de 10.1..am trying to resolve from 3 days but still ..my project works good in xcode9.1..
@ArunaM Did you try the above steps which I have given in the answer? What was the status after doing this?
This was the solution when I removed a ViewController from the project which caused same error!
V
Vicky

Follow the steps:

1) First Click your story board

2) Then Click File Inspector

3) Then select "Target Membership"

https://i.stack.imgur.com/3qxHW.png


佚名

The simulator is not case sensitive, but the device is. If your storyboard is called MainStoryboard, not MainStoryBoard, this will cause your problem. and aslo * dont use the extensions write only the story board name

main.storyboard -> only main is the storyboard name


n
nomnom

Swift 5.1 & xCode 11.2

In my case, I forgot to change Storyboard Name in Info.plist

https://i.stack.imgur.com/Z48UN.png

Info.plist source code

    <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>AccountViewController</string>
                </dict>
            </array>
        </dict>
    </dict>

N
Neha Vipin

Also, try removing the Storyboard name

https://i.stack.imgur.com/PGLlb.png


u
user1195202

Open you storyboard file Then Click File Inspector Then select "Target Membership" and check your project Do the same for ViewController file !!!important part if you use ViewController.swift or ViewController.m with your storyboard!!!


s
saumya ranjan Gangwar

This error come, while you recover your main.storyboard file from trash after delete your file. I also faced same issue yesterday.

You have to set the location path of the main.storyboard as Relative to Group in file inspector of main.storyboard. After that in the same attribute, you have to insure the check mark on your app target(As you can see in attached picture).

https://i.stack.imgur.com/RTCQk.png


L
LentoMan

Two different solutions that worked for me after upgrading to Xcode 10.1:

In File->Workspace (or Project) Settings. Switch to Legacy Build System.

In your targets Build Phases, remove the Base.lproj folder from Copy Bundle Resources (if listed) and make sure each of your storyboards are listed and copied separately instead.

After applying either of the fixes above make sure you Clean Build Folder from the Product menu once, otherwise the fixes might not work properly.


s
seashore liu

Deleting row in plist caused black screen in my app too. And I fixed it by enabling target membership of the storyboard


M
Mavin Martin

As Kalpit Gajera has said, "open the info.plist of your project and remove the selected row displayed in screenshot". You simply remove 'Main storyboard file base name' from the Info.plist. After you remove it, clean and run, the program will no longer fail but will show a black screen. Open Info.plist again and manually add the row back in. Problem solved.


S
Sagar Thukral

If still you have black screen, then try adding below code in your scene delegate

willConnectTo

    guard let windowScene = (scene as? UIWindowScene) else { return }
    window = UIWindow(frame: windowScene.coordinateSpace.bounds)
    window?.windowScene = windowScene
    let navController = UINavigationController()
    let mainstoryboard:UIStoryboard = UIStoryboard(name: "Your storyboard name", bundle: nil)
    let initialController = mainstoryboard.instantiateViewController(withIdentifier: "your initial controller Identifier") as! initialController
    navController.addChild(initialController)
    window?.rootViewController = navController
    window?.makeKeyAndVisible()

C
Chris

choose main.storyboard, change the view as iOS 6.1 and earlier, then xcode will tell u what u need to do.

https://i.stack.imgur.com/PfLjW.png


S
Sven Vietense

My solution is:

When i added a Seque Connection between two Views and in the Projekt Configuration the Deployment Target is less then 8.0 i get this error.

ok, easy understanding when you develop for IOS 6.0 (for example) you can't use Seque, because the Seque needs IOS 8.0 or later...... ;-)

so, i set the Deployment Target to 8.0 and the error is gone !!!! other while, i cancel all the Segue Connections and handle it with IBAction, old school ;-)


C
Community

I was moving Main.Storyboard file to "blue" sub folder which was causing issues, I had to add sub folders following these instructions Xcode 6.3 New File Issue

then moving Main.Storyboard file to yellow sub folder did work for me


F
Francesco Boi

My issue was resolved by removing the .xml suffix from the Main.storyboard.xml file.

Apparently, the suffix changed from the version from which I imported the project.

Therefore, renaming the file (removing the .xml suffix) and restarting, then Project-> clean.... fixed the problem.


S
Sk Borhan Uddin

https://i.stack.imgur.com/k9lzk.png

https://i.stack.imgur.com/v5yrx.png


J
JESTIN SAJI

Note: If some ViewControllers are missing "Could not find a storyboard named 'ReceiverViewController' in bundle" you can add the name of ViewController in storyBoard id and use the code below for navigation

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyBoard.instantiateViewController(withIdentifier: "ReceiverViewController") as! ReceiverViewController
    self.navigationController?.pushViewController(vc, animated: true)

i
iSpeedyG

Ok this has been a process. Trying so many different things. Running xcode 6.4 on OS 10.11. Having the cannot find 'Main' problem. What I finally did was move the main.storyboard off on too my desktop from Finder.Did a clean and build and quit xcode. restarted xcode now it has a red main.storyboard. i run it virtually does the same thing. then I right click on the project folder and choose the option add files to... Browse to where it is and open it. then when it is there to the right should be the identities inspector. click on the small folder under location. browse to that folder again and select choose. Then I ran and it worked. Amen !!!


A
Akashascosset

Select the view controller you want to first show up in the list on the left side of the storyboard, then in the attribute inspector make sure its title is "Main" and the checkbox for "Is Initial View Controller" is selected.


K
Kerak

In my case this was due to a Pod library that was outdated

Deleting the /Pods folder and doing pod install fixed it for me


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now