xcode 故事板例外 - 故事板不包含带有标识符的视图控制器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25434755/
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-09-15 05:25:44  来源:igfitidea点击:

STORYBOARD EXCEPTION - Storyboard doesn't contain a view controller with identifier

iosxcodestoryboard

提问by origds

I am currently developing an iOS application for both iPhone and iPad. I'm trying to show a NavigationController to make a module that shows files. In an iPhone it works just fine, but I can′t get it to work in iPad.

我目前正在为 iPhone 和 iPad 开发 iOS 应用程序。我试图展示一个 NavigationController 来制作一个显示文件的模块。在 iPhone 上它工作得很好,但我不能让它在 iPad 上工作。

I'm getting the following error:

我收到以下错误:

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

and this is the code:

这是代码:

case 10: // Files
{
  UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"FilesNavigation"];

  FilesViewController *filesViewController = [storyboard instantiateViewControllerWithIdentifier:@"Files"];

  [navigationController pushViewController:filesViewController animated:YES];

  self.slidingViewController.topViewController = navigationController;

  break;
}

And in my storyboard I have already set the Storyboard ID for the navigation controller.

在我的故事板中,我已经为导航控制器设置了故事板 ID。

>##Custom Class 
>Class: UINavigationController
>##Identity
>Storyboard ID: FilesNavigation

I used this code for another case on the switch/case block for other module and it works for iPad too, its the first time that I have this error.

我将此代码用于其他模块的开关/外壳块上的另一个案例,它也适用于 iPad,这是我第一次遇到此错误。

回答by origds

I figured it out, the problem was that the Storyboard wasn't updating in the device.

我想通了,问题是故事板没有在设备中更新。

  1. Uninstall the app from the simulator/iPhone/iPad
  2. Product > Clean
  3. Build & Run
  1. 从模拟器/iPhone/iPad 卸载应用程序
  2. 产品 > 清洁
  3. 构建和运行

As stated in @T0m_Twt's answer in this question

如@T0m_Twt 在这个问题中的回答所述

回答by meda

In the right pane, in the identity inspector section give a storyboard Id to your Navigation Controller.

在右侧窗格中的身份检查器部分,为您的导航控制器提供故事板 ID。

I took a screenshot for you

我截图给你

enter image description here

在此处输入图片说明

回答by Nix Wang

Here's another case:

这是另一个案例:

There are two localized storyboards.Only one of them has the view controller you want.

有两个本地化的故事板。其中只有一个拥有您想要的视图控制器。

回答by Justin Holman

By chance, do you have a storyboard for iPhone and a different one for iPad? If you do, then the iPad one might not have a storyboard with that identifier. Also when running on an iPad, set a break point in your code and verify what your "storyboard" object is.

碰巧,你有一个适用于 iPhone 的故事板和一个不同的适用于 iPad 的故事板吗?如果您这样做了,那么 iPad 可能没有带有该标识符的故事板。同样在 iPad 上运行时,在代码中设置一个断点并验证您的“故事板”对象是什么。

I use a category on UIStoryboard that will give me the storyboards for each platform.

我在 UIStoryboard 上使用了一个类别,它将为我提供每个平台的故事板。

I can use [UIStoryboard storyboardHome] and that will determine if it needs iPad or iPhone specific and return that to me. I also ensure my storyboards follow proper naming. So I would have Home_iPad and Home_iPhone.

我可以使用 [UIStoryboard storyboardHome],这将确定它是否需要特定于 iPad 或 iPhone 并将其返回给我。我还确保我的故事板遵循正确的命名。所以我会有 Home_iPad 和 Home_iPhone。

回答by superarts.org

TL;DR - clear everything and remove old version of the app as well, if there's any.

TL;DR - 清除所有内容并删除旧版本的应用程序,如果有的话。

It may sound crazy, but suppose that if you have changed target name which changed bundle name as well, you might have both the old and new version of the app installed in the simulator / device, and this might cause trouble for the UIStoryboardinstance failed to instantiate some view controllers, which might eventually cause the trouble described in the question. To solve it, you need to remove all related apps or simply reset the simulator / device.

这听起来可能很疯狂,但是假设您更改了目标名称,也更改了包名称,那么您可能在模拟器/设备中安装了新旧版本的应用程序,这可能会导致UIStoryboard实例失败的麻烦实例化一些视图控制器,这最终可能会导致问题中描述的问题。要解决它,您需要删除所有相关应用程序或简单地重置模拟器/设备。