ios 故事板不包含带有标识符的视图控制器

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

Storyboard doesn't contain a view controller with identifier

iosobjective-cxcodestoryboard

提问by Mat

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 identifieron the UIStoryboardbut I'm still getting this error.

我已经设置了identifierUIStoryboard但我仍然收到这个错误。

enter image description here

在此处输入图片说明



采纳答案by Mat

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:

固定的!不仅必须设置 segue 中的标识符,在我的情况下为 DrivingDetails,而且我的 tableViewController 中的标识符必须设置为 DrivingDetails...检查我的图片:

enter image description here

在此处输入图片说明

I also removed the navigation view controller so now the 2 table view controllers are connected directly with a "push" animation.

我还删除了导航视图控制器,所以现在 2 个表视图控制器直接与“推送”动画连接。

*****EDIT for XCODE 7.0*****

*****编辑 XCODE 7.0*****

you have to set the storyboardId(in this case the viewController is embedded in a Navigation controller:

您必须设置 storyboardId(在这种情况下,viewController 嵌入在导航控制器中:

let lastMinVc  = mainStoryBoard.instantiateViewControllerWithIdentifier("lastMinuteNavController") as! UINavigationController

enter image description here

在此处输入图片说明

回答by khaliq

Just for future reference:

仅供参考:

I'm developing on iOS 6 using Storyboards.

我正在使用 Storyboards 在 iOS 6 上进行开发。

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.

我遇到了同样的问题,但在检查器中找不到“标识符”字段。相反,只需将名为“Storyboard ID”的字段设置为您要命名的标识符。该字段可以在检查器中的“显示身份检查器”选项卡下找到。

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

[注意 - 下面的评论表明有些人发现他们需要(也?)在检查器中的故事板 ID 正下方设置“恢复 ID”字段。单击“使用故事板 ID”似乎还不够。]

There's an image below for reference: (in this instance I've named my identifier the same as my class) enter image description here

下面有一张图片供参考:(在这种情况下,我将我的标识符命名为与我的班级相同) 在此处输入图片说明

回答by Ted

In Xcode 7 - 11,

Xcode 7 - 11 中

when you change storyboard IDs and you get errors like this,

当您更改情节提要 ID 并出现这样的错误时,

just CLEANyour project (CMD+SHIFT+K)

只是CLEAN项目(CMD+ SHIFT+ K

回答by Rafael

let storyboard = UIStoryboard(name: "StoryboardFileName", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "StoryboardID")
self.present(controller, animated: true, completion: nil)

Note:

笔记:

  • "StoryboardFileName"is the filenameof the Storyboard and notthe ID of the storyboard!
  • "StoryboardID"is the ID you have manuallyset in the identity inspector for that storyboard (see screenshot below).
  • "StoryboardFileName"是故事板的文件名不是故事板的 ID!
  • "StoryboardID"是您在身份检查器中为该情节提要手动设置的 ID (请参见下面的屏幕截图)。

Storyboard ID

故事板 ID

Sometimes people believe that the first one is the Storyboard ID and the second one the View Controller class name, so note the difference.

有时人们认为第一个是 Storyboard ID,第二个是 View Controller 类名,所以请注意区别。

回答by BeyazBaron

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

Identity 位于为 Xcode 6.3.2 命名为 Storyboard ID 的 Identity Inspector 选项卡中,并选中了 Use Storyboard ID 选项。 在此处输入图片说明

回答by Hari Karam Singh

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 withthe new VC in each of them.

在向情节提要中添加新 VC 后才遇到此问题,但仅在设备上,而不是在模拟器上。原来这是因为有多个故事板本地化 - VC 只添加到主要的。我尝试删除其他本地化(其中一个是我的 iPhone 使用的),但仍然有错误。最后,我不得不新的 VC重新创建其他本地化。

回答by confitz20

For those with the same issue as @Ravi Bhanushali, here is a Swift 4 solution:

对于那些与@Ravi Bhanushali 有相同问题的人,这里有一个 Swift 4 解决方案:

let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)

let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)

回答by Ravi Bhanushali

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 fileon which we work is named as Main.storyboard. So we need to have reference of object of the Main.storyboard.

这里创建的故事板的对象不是包含我们的 ViewControllers 的主故事板。由于故事板文件上,我们的工作被命名为 Main.storyboard。所以我们需要引用Main.storyboard的对象。

Use following code for that :

为此使用以下代码:

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

Here storyboardWithNameis the name of the storyboard file we are working with and bundlespecifies the bundle in which our storyboard is (i.e. mainBundle).

storyboardWithName是我们正在使用的故事板文件的名称,并bundle指定我们的故事板所在的包(即mainBundle)。

回答by aychen0110

Modifying "Storyboard ID" in the identity inspector (the 3rd icon to the left) should work.

在身份检查器(左侧的第三个图标)中修改“故事板 ID”应该可以工作。

If not and you're sure there's no typo, try cleaning up the project ("Product"->"Clean", or simply command + shift + K).

如果没有,并且您确定没有打字错误,请尝试清理项目(“产品”->“清理”,或者只是命令 + shift + K)。

回答by Jon

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

我找到了它...单击情节提要中的视图控制器,单击 vc 属性检查器左侧的第三个图标 - 您在该屏幕上设置呼叫名称的那个它说“身份” - 我的被隐藏了,我不得不单击“身份”一词,然后显示 storyboardID - 从代码中添加标识符,完成