ios 在捆绑 NSBundle 中找不到名为“MainStoryBoard”的故事板

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8694742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:05:30  来源:igfitidea点击:

Could not find a storyboard named 'MainStoryBoard' in bundle NSBundle

iphoneiosxcode-storyboard

提问by chriskievit

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

几天前我启动了一个新应用程序并开始使用模拟器来测试它。我从一个空项目开始并手动添加了故事板。模拟器构建并运行我的应用程序很好,但是当我尝试构建到我的 iPhone 时,我收到消息“在捆绑 NSBundle 中找不到名为‘MainStoryBoard’的故事板”。

Google turned up nothing and this questionsuggested 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?

任何人都可以指出我正确的方向吗?

采纳答案by jrturton

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

模拟器不区分大小写,但设备区分大小写。如果您的故事板被称为 MainStoryboard,而不是 MainStoryBoard,这将导致您的问题。

回答by Sushma Satish

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

我的应用程序在 iPhone 模拟器上正常工作,但奇怪的是 Xcode 停止响应,我不得不强制退出 Xcode。当我重新启动 Xcode 时,我遇到“找不到名为 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.
  1. 将“MainStoryboard.storyboard”重命名为“MainStoryboard_1.storyboard”
  2. 打开位于“支持文件”文件夹中的文件“$your_app$-Info.plist”。将“主故事板文件基本名称”编辑为“MainStoryboard_1.storyboard”。
  3. 重新运行应用程序,它对我有用。
  4. 我将我的故事板文件重命名回原来的“MainStoryboard.storyboard”。
  5. 将 .plist 文件编辑回原始文件。
  6. 重新运行应用程序,它对我有用。

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.

出于某种原因,在强制退出 Xcode 后无法识别文件“MainStoryboard.storyboard”,并且按照上述步骤使应用程序再次识别该文件。

Hope this solution helps..

希望这个解决方案有帮助..

回答by Ilya K.

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.

只想提一下我遇到的场景。我不知道怎么做,但故事板与目标断开连接,尽管它仍然是项目的一部分。为了解决这个问题,我打开了故事板,选择了“文件检查器”(右侧面板上最左边的图标)并检查“目标成员资格”下的项目。希望它可以帮助某人。

回答by Igotit

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.

例如,您在项目设置中指定了 zh-CN 本地化,但在 en-US 下运行模拟器。

回答by Jayprakash Dubey

Tried all solutions mentioned above but didn't worked.

尝试了上面提到的所有解决方案,但没有奏效。

After thorough research found the culprit:

经过深入研究找到了罪魁祸首:

Copy Bundle Resource was missing from TARGETS -> Build Phases

TARGETS -> Build Phases 中缺少 Copy Bundle Resource

This got accidentally removed while removing Cocoapods.

这在删除 Cocoapods 时被意外删除。

Below are steps to fix this :

以下是解决此问题的步骤:

  1. Go to TARGETSof your project
  2. Click on plus (+) buttonpresent 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
  1. 转到TARGETS您的项目
  2. 点击plus (+) button左上角的礼物
  3. 从下拉列表中选择新的复制捆绑资源
  4. 现在,添加您Storyboard files (Main, Launchscreen etc).还要添加 Assets 文件夹。您可以通过单击底部的加号 (+) 按钮来添加这些文件

screenshot

截屏

  1. Delete the derived data content
  2. Delete the appfrom Simulator/Device and run again
  1. 删除 derived data content
  2. Delete the app从模拟器/设备并再次运行

回答by Nitin Alabur

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

这帮助我(Swift 2.1,Xcode 7.2)使用标签栏的应用程序

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

我的 Main.storyboard 具有正确的目标成员资格、复制捆绑资源、清理构建文件夹等(大多数答案都指向这一点)。

回答by Venkatesh G

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.

我想你可能已经删除了故事板并决定在初始应用程序启动时使用 .xib 文件。在这种情况下,Xcode 会尝试找到一个不存在的故事板。

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

对于这种情况,单击项目Info>>Custom iOS Target Properties并删除此键值对: Main storyboard file base name

回答by Raphael Royer-Rivard

A simple Clean corrected the error for me.

一个简单的 Clean 为我纠正了错误。

回答by abdul sathar

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

人们通常会输入“Main.storyboard”作为名称,因为这实际上是文件的名称,但对于 Obj-C 编码而言,“X.storyboard”的名称为“X”,因此在这种情况下, @“主要的”。

回答by manroe

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

Nitin Alabur的回答帮助了我,但间接地帮助了我。发布另一个答案以澄清:

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

我忽略了NSBundle这些东西,因为,嘿,我不知道捆绑包是什么鬼。事实证明这对于这个用例很重要,其中故事板将存在于应用程序的“捆绑包”之外(而是在我的框架的捆绑包中)。这段代码将告诉 iOS 在当前类所在的包中找到故事板(对我来说,它是包含我的框架的包):

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:[NSBundle bundleForClass:[self class]]];