ios Storyboard uiviewcontroller,“自定义类”未显示在下拉列表中

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

Storyboard uiviewcontroller, 'custom class' not showing in drop down

iosstoryboard

提问by 1dayitwillmake

I have a UIViewController I created in my apps storyboard, as well as a custom UIViewController subclass which I added to the project (and is correctly in the compile phase for my target). However when I go to set the 'Custom Class' property on the view-controller in Storyboard my custom class does not show up on the list.

我在我的应用程序故事板中创建了一个 UIViewController,以及一个我添加到项目中的自定义 UIViewController 子类(并且正确地处于我的目标的编译阶段)。但是,当我在 Storyboard 的视图控制器上设置“自定义类”属性时,我的自定义类没有显示在列表中。

  • Checked that the class is part of my app's target, not tests'
  • Double checked that it is correctly a subclass of UIViewController
  • Compiled program just to make sure xcode was working with latest information
  • Restarted xcode
  • 检查该类是我的应用程序目标的一部分,而不是测试的一部分
  • 仔细检查它是否正确是 UIViewController 的子类
  • 编译程序只是为了确保 xcode 使用最新信息
  • 重启xcode

What would cause my class to not show up in the 'Custom Class' drop down?

什么会导致我的班级不显示在“自定义班级”下拉列表中?

采纳答案by ejkujan

Two ways I found that solve the problem but they are work arounds. 1. Just type the view controllers name in the text field, or 2. close the project and then reopen it and in the project initialization it places the file on the list.

我发现有两种方法可以解决问题,但它们是变通方法。1. 只需在文本字段中输入视图控制器名称,或 2. 关闭项目,然后重新打开它,在项目初始化时将文件放在列表中。

回答by Bobinoh

If you still have your problem or for those who could have the same problem:

如果您仍然有问题或对于那些可能有同样问题的人:

Make sure to select on your storyboard your "ViewController" instead of your "View" (which is automatically selected when you click on the view in the storyboard). The difference between those two is that when the view controller is selected, a blue rectangle pop up around your app. To be sure to select the view controller, open the document outline and select it directly in your storyboard hierarchy.

确保在情节提要上选择“ViewController”而不是“视图”(单击情节提要中的视图时会自动选择)。The difference between those two is that when the view controller is selected, a blue rectangle pop up around your app. 要确保选择视图控制器,请打开文档大纲并直接在故事板层次结构中选择它。

enter image description hereenter image description hereenter image description here

在此处输入图片说明在此处输入图片说明在此处输入图片说明

回答by tiguero

I would try the following:

我会尝试以下方法:

  1. Check that the file implementing the class is part of the build phases(check under target> build phases)
  2. Add the .mfile to build phases(if it isn't already).
  3. Restart Xcode.
  1. 检查实现类的文件是否是构建阶段的一部分(在target> build phase下检查)
  2. .m文件添加到构建阶段(如果还没有)。
  3. 重新启动Xcode。

回答by Bill Hollings

You can fix this by editing the XML of your Storyboard.

您可以通过编辑 Storyboard 的 XML 来解决此问题。

  1. Right-click your My.storyboardentry in the Project Navigatorpanel and select the Open As->SourceCodemenu choice. Find your view controller entry in the XML, and add the attribute customClass="MyController".

  2. Save the storyboard.

  3. Right-click your My.storyboardentry in the Project Navigatorpanel again, and select the Open As->Interface Builder - Storyboardmenu choice.

  1. My.storyboardProject Navigator面板中右键单击您的条目并选择Open As->SourceCode菜单选项。在 XML 中找到您的视图控制器条目,并添加属性customClass="MyController"

  2. 保存故事板。

  3. 再次右键单击Project Navigator面板My.storyboard中的条目,然后选择Open As->Interface Builder - Storyboard菜单选项。

The custom class entry will now contain your MyControllerclass name.

自定义类条目现在将包含您的MyController类名。

回答by mikeborgh

Make sure your class inherits from UIViewController.

确保您的类继承自 UIViewController。

@interface ClassName : UIViewController

回答by Matt Foley

In Xcode 8, a few of my classes had the wrong path (case sensitive) specified for their file locations.

在 Xcode 8 中,我的一些类为其文件位置指定了错误的路径(区分大小写)。

MyProject/mysubdirectory/MyViewController.xib (.m, .h)

vs:

对比:

MyProject/MySubdirectory/MyViewController.xib (.m, .h)

Really not sure how it ended up in that state, but my project exhibited the exact same behavior as above (no outlets/actions displaying in IB), and fixing that path fixed the problem.

真的不确定它是如何最终处于那种状态的,但我的项目表现出与上述完全相同的行为(IB 中没有显示出口/动作),并且修复该路径解决了问题。

I fixed this two different ways. One way was by I opened the .pbxproj file and fixing the case sensitive issue manually. The other way that worked was by tapping the folder icon under the Identity and Type section of the File Inspector tab of the file, and re-selecting the file there.

我修复了这两种不同的方式。一种方法是我打开 .pbxproj 文件并手动修复区分大小写的问题。另一种有效的方法是点击文件“文件检查器”选项卡的“身份和类型”部分下的文件夹图标,然后在那里重新选择文件。

回答by KJBoffo

I had been having the same issues as described in this problem. However, none of the suggested answers fixed it for me. My project compiled OK without warnings or errors, but, in the .h file there were no 'outlet' indicators to indicate that my outlets had been linked to storyboard elements.

我遇到了与此问题中描述的相同的问题。但是,没有一个建议的答案为我解决了这个问题。我的项目编译正常,没有警告或错误,但是,在 .h 文件中没有“出口”指示符来表明我的出口已链接到故事板元素。

Additionally, attempts to create new outlets in my code, by right-click and dragging into my header file, were not recognising my header source as a potential target for this operation. And furthermore, my Class did not make an appearance in the Custom-Class dropdown for the ViewController's property inspector panel.

此外,尝试通过右键单击并拖动到我的头文件中来在我的代码中创建新的出口,并没有将我的头源识别为该操作的潜在目标。此外,我的类没有出现在 ViewController 的属性检查器面板的自定义类下拉列表中。

And yet, the project compiled OK.

然而,该项目编译正常。

Closer examination showed that I had defined my own class in the following manner...

仔细检查表明我已经以下列方式定义了我自己的类......

@interface KJBMainDataViewTrackConMk2<UIScrollViewDelegate> : UIViewController

which apparently compiles nicely.

这显然编译得很好。

But, if this is changed to the following, (moving the protocols to the end)...

但是,如果将其更改为以下内容,(将协议移到最后)...

@interface KJBMainDataViewTrackConMk2 : UIViewController<UIScrollViewDelegate>

Then everything springs to life. All outlets are suddenly indicated as being 'connected' with a storyboard element. And right-click dragging starts to work again, and my custom class appears in the custom-class drop-down in the property inspector panel for the storyboard ViewController!

然后一切都焕然一新。所有出口突然被指示为与故事板元素“连接”。然后右键拖动又开始工作了,我的自定义类出现在storyboard ViewController 的属性检查器面板的自定义类下拉列表中!

Other answers here probably represent the most likely causes of this condition, but, I felt it worth mentioning at least this one other potential cause.

这里的其他答案可能代表了这种情况的最可能原因,但是,我觉得至少值得一提的是另一个潜在原因。

回答by Chris Livdahl

I had the same problem, but none of the other solutions worked for me. The issue for me was that I had a Mac and iOS target, both with their own versions of the same view controller. For example, I had a .h/.m pair of files named FooViewController for Mac and another .h/.m pair of files named FooViewController for iOS. Each pair was properly included with their respective targets, but for some reason Xcode does not like it and my view controller would not show up in the Custom Class dropdown in the view controller in the storyboard. I ended up renaming my class in the iOS view controller and it immediately showed up in the dropdown.

我遇到了同样的问题,但其他解决方案都不适合我。对我来说,问题是我有一个 Mac 和 iOS 目标,两者都有自己的同一个视图控制器版本。例如,我有一对 .h/.m 文件名为 FooViewController for Mac 和另一对 .h/.m 文件名为 FooViewController for iOS。每对都正确地包含在各自的目标中,但由于某种原因 Xcode 不喜欢它,我的视图控制器不会显示在故事板视图控制器的自定义类下拉列表中。我最终在 iOS 视图控制器中重命名了我的类,它立即出现在下拉列表中。

回答by heyjude

In my case, I drag a new TableViewController object to the storyboard, but I add a new file which's subclass is "UIViewController".... Then, I add a file which's subclass is "UITableViewController", problem solved!!

在我的例子中,我将一个新的 TableViewController 对象拖到情节提要上,但是我添加了一个新文件,它的子类是“UIViewController”......然后,我添加了一个子类是“UITableViewController”的文件,问题解决了!!

回答by sirhcmcd

Click on a different view controller in the storyboard, then click on it's custom class pulldown to confirm the new class is listed, but don't select it. Click back on the new view controller you made and you should see it now listed in its custom class pulldown menu. odd, eh? just forces a refresh I think.

单击故事板中的不同视图控制器,然后单击它的自定义类下拉列表以确认新类已列出,但不要选择它。单击您创建的新视图控制器,您应该会看到它现在列在其自定义类下拉菜单中。奇怪,嗯?我认为只是强制刷新。