Unable to see custom classes in Interface Builder

2019-05-10 16:14发布

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

Symptoms:

  • When using the IB drop down to choose a custom class, none of the custom classes appear.
  • IB_DESIGNABLE and IBInspectable 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 as IB_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

How can I fix this?

5条回答
贪生不怕死
2楼-- · 2019-05-10 16:50

This is what worked for me: enter image description here

I somehow lost the view reference, so all i did was to drag from a little circle "New Referencing Outlet" to the main view of the .xib, and BOOM!

查看更多
走好不送
3楼-- · 2019-05-10 16:52

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.

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.

Things I tried that didn't work:

  • Naming the subclass according to Apple's conventions (e.g. instead of View use ABCTestView).
  • 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).

Related discussions:

查看更多
相关推荐>>
4楼-- · 2019-05-10 16:52

Here are some possible solutions:

When using the IB drop down to choose a custom class, none of the custom classes appear.

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_DESIGNABLE and IBInspectable 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 as IB_DESIGNABLE.

If the view does not begin as a Custom View either dragged from the Object library or created from Editor > Embed In > ..., for some reason changing the Custom Class in 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:

<view ... customClass="YourView">
    ...
</view>

Change view to customView so that the entry resembles:

<customView ... customClass="YourView">
    ...
</customView>

then right-click the .xib again and choose Open As > Interface Builder XIB Document and you should now see a Designables entry under Custom Class in the Identity inspector of IB and Debug Selected Views will be available under the Editor menu.

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

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 Control and 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.

查看更多
Root(大扎)
5楼-- · 2019-05-10 16:59

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.

查看更多
放我归山
6楼-- · 2019-05-10 17:09

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:

Before (not functioning: Designables did not appear and Interface Builder did not render my class):

IB_DESIGNABLE

@class MyCustomClass;

@interface MyCustomView : UIView

After (functioning: Designables did appear and Interface Builder did render my class):

@class MyCustomClass;

IB_DESIGNABLE @interface MyCustomView : UIView

So it appears that Xcode is very sensitive to the order of things.

查看更多
登录 后发表回答