xcode 无法在 Interface Builder 下拉菜单中看到自定义类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28386081/
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
Unable to see custom classes in Interface Builder drop down
提问by Senseful
I'm using Xcode 6.1.1, and cannot select my custom class from the drop down. Because of this, I believe it is causing several other related issues (see below).
我使用的是 Xcode 6.1.1,无法从下拉列表中选择我的自定义类。因此,我相信它会导致其他几个相关问题(见下文)。
Symptoms:
症状:
- When using the IB drop down to choose a custom class, none of the custom classes appear.
IB_DESIGNABLE
andIBInspectable
do not work: When selecting the control in IB, the "Designable" status does not appear; none of the inspectable properties appear either. Debug selected views option is grayed out when selecting a view which is defined asIB_DESIGNABLE
.- Ctrl-dragging items to create connections (IBOutlet and IBAction) from IB to source code occasionally doesn't allow you to "drop" the connection into the class's source code (as if there is a class mismatch). (Note: This assumes you manually typed in the class name in the Custom Class section.)
- Suspected to be related: WatchKit: unable to find interface controller class
- 使用 IB 下拉菜单选择自定义类时,不会出现任何自定义类。
IB_DESIGNABLE
并且IBInspectable
不起作用:在IB中选择控件时,不出现“Designable”状态;也没有任何可检查的属性出现。选择定义为IB_DESIGNABLE
.- 按住 Ctrl 键拖动项目以创建从 IB 到源代码的连接(IBOutlet 和 IBAction),有时不允许您将连接“放入”类的源代码中(就像类不匹配一样)。(注意:这假设您在自定义类部分中手动输入了类名。)
- 疑似相关:WatchKit:找不到接口控制器类
How can I fix this?
我怎样才能解决这个问题?
回答by Senseful
Things that worked:
有用的东西:
- Try on another machine. (This leads me to believe the machine has some setting that is messing this up.)
- Reinstall Xcode.
- Moving the project to a new location (in this case a git repository), fixed it once.
- 在另一台机器上试试。(这让我相信这台机器有一些设置把它搞砸了。)
- 重新安装Xcode。
- 将项目移动到新位置(在本例中为 git 存储库),修复了一次。
Things I tried that didn't work (but have worked for others):
我尝试过但不起作用的事情(但对其他人有用):
- Restart Xcode
- Restart machine (this worked once before, not this time)
- Create a new storyboard.
- Create a new subclass (not just rename it).
- Create a new project via Apple's single view template.
- Cleaning the project
- Deleting derived data
- Reindex the project
- Remove localization on the storyboard file.
- 重启Xcode
- 重新启动机器(这之前工作过一次,这次不行)
- 创建一个新的故事板。
- 创建一个新的子类(不仅仅是重命名)。
- 通过 Apple 的单一视图模板创建一个新项目。
- 清理项目
- 删除派生数据
- 重新索引项目
- 删除情节提要文件上的本地化。
Things I tried that didn't work:
我尝试过但不起作用的事情:
- Naming the subclass according to Apple's conventions (e.g. instead of
View
useABCTestView
). - Import the .h of the class in the .h and .m of the view controller.
- Try on another version of Xcode, which is already installed (beta 6.2).
- 根据 Apple 的约定命名子类(例如,而不是
View
useABCTestView
)。 - 在视图控制器的 .h 和 .m 中导入类的 .h。
- 尝试使用已安装的另一个版本的 Xcode(测试版 6.2)。
Related discussions:
相关讨论:
回答by Huntario
This wasn't your specific situation but I was in a similar "rip my hair out" moment. When creating custom controller classes and using the interface builder, you must make sure to click the yellow button at the top of the view you're working with (the view controller button). Otherwise the custom ViewController class won't show up in the custom class drop down menu within the identity inspector.
这不是你的具体情况,但我处于类似的“扯掉我的头发”时刻。创建自定义控制器类并使用界面构建器时,您必须确保单击您正在使用的视图顶部的黄色按钮(视图控制器按钮)。否则自定义 ViewController 类将不会显示在身份检查器的自定义类下拉菜单中。
回答by Tim Friedland
回答by Tim Camber
One thing that worked for me after inexplicably seeing the issue where the "Designables" row would not appear in the Custom Class section of the Identity Inspector:
在莫名其妙地看到“Designables”行不会出现在身份检查器的“自定义类”部分中的问题后,对我有用的一件事:
Before (not functioning: Designables did not appear and Interface Builder did not render my class):
之前(不起作用:Designables 没有出现并且 Interface Builder 没有呈现我的类):
IB_DESIGNABLE
@class MyCustomClass;
@interface MyCustomView : UIView
After (functioning: Designables did appear and Interface Builder did render my class):
之后(运行:Designables 确实出现并且 Interface Builder 确实呈现了我的类):
@class MyCustomClass;
IB_DESIGNABLE @interface MyCustomView : UIView
So it appears that Xcode is very sensitive to the order of things.
所以看起来Xcode对事物的顺序非常敏感。
回答by notedible
Here are some possible solutions:
以下是一些可能的解决方案:
When using the IB drop down to choose a custom class, none of the custom classes appear.
使用 IB 下拉菜单选择自定义类时,不会出现任何自定义类。
Manually type the name of your custom class instead of trying to find it in the dropdown. Sometimes IB will autocomplete the name of the class as you type, especially if you follow Apple's conventions, i.e. YourView as a subclass of NSView.
手动输入自定义类的名称,而不是尝试在下拉列表中找到它。有时 IB 会在您键入时自动完成类的名称,尤其是如果您遵循 Apple 的约定,即 YourView 作为 NSView 的子类。
IB_DESIGNABLE
andIBInspectable
do not work: When selecting the control in IB, the "Designable" status does not appear; none of the inspectable properties appear either. Debug selected views option is grayed out when selecting a view which is defined asIB_DESIGNABLE
.
IB_DESIGNABLE
并且IBInspectable
不起作用:在IB中选择控件时,不出现“Designable”状态;也没有任何可检查的属性出现。选择定义为IB_DESIGNABLE
.
If the view does not begin as a Custom View either dragged from the Object libraryor created from Editor > Embed In > ..., for some reason changing the Custom Classin the Identity inspector doesn't make a difference. To fix this, right-click the .xib and choose Open As > Source Code. Search for the view you want to fix (giving your view a label that is easily identifiable in IB will make this easier). You will find an entry like this:
如果视图不是从对象库拖动或从Editor > Embed In > ...创建的自定义视图开始,则出于某种原因在身份检查器中更改自定义类不会产生任何影响。要解决此问题,请右键单击 .xib 并选择Open As > Source Code。搜索您想要修复的视图(给您的视图一个在 IB 中易于识别的标签将使这更容易)。你会发现这样的条目:
<view ... customClass="YourView">
...
</view>
Change view
to customView
so that the entry resembles:
更改view
为customView
使条目类似于:
<customView ... customClass="YourView">
...
</customView>
then right-click the .xib again and choose Open As > Interface Builder XIB Documentand you should now see a Designablesentry under Custom Classin the Identity inspector of IB and Debug Selected Viewswill be available under the Editormenu.
然后再次右键单击 .xib 并选择Open As > Interface Builder XIB Document,您现在应该在 IB 的身份检查器中的Custom Class下看到一个Designables条目,并且Debug Selected Views将在Editor菜单下可用。
Ctrl-dragging items to create connections (IBOutlet and IBAction) from IB to source code occasionally doesn't allow you to "drop" the connection into the class's source code (as if there is a class mismatch). (Note: This assumes you manually typed in the class name in the Custom Class section.)
按住 Ctrl 键拖动项目以创建从 IB 到源代码的连接(IBOutlet 和 IBAction),有时不允许您将连接“放入”类的源代码中(就像类不匹配一样)。(注意:这假设您在自定义类部分中手动输入了类名。)
Doesn't sound like your exact problem, but on a dual-monitor/multi-monitor setup, if IB is on a different monitor from the source code window, go to Apple menu > System Preferences... > Mission Controland uncheck Displays have separate Spaces. This may have some visual side-effects (like window drop-shadows bleeding into other monitors) but it will fix the problem of ctrl-dragging onto a separate monitor.
听起来不像您的确切问题,但在双显示器/多显示器设置中,如果 IB 位于与源代码窗口不同的显示器上,请转到Apple 菜单 > 系统偏好设置... > 任务控制并取消选中显示有单独的空间。这可能会产生一些视觉副作用(例如窗口阴影渗入其他显示器),但它会解决按住 ctrl 拖动到单独显示器上的问题。