Why Aren't My Custom Classes Appearing in the Dropdown in Interface Builder

Custom class is neither appearing in suggestion box of interface builder nor being assigned to View controller

Your custom view controller class must be a subclass of UIViewController.

Custom class is neither appearing in suggestion box of interface builder nor being assigned to View controller

Your custom view controller class must be a subclass of UIViewController.

Why does Interface Builder not show a view controller subclass in the identity inspector?

Pretty simple: You can't use a generic type here. The reason is that UIKit is written in ObjC, and generic types are not fully visible to ObjC. This answer goes into the details.

Xcode - Custom classes aren't working

Make sure your new .m files are in the Compile Sources list of Build Phases.

  • Click your project icon in the project navigator
  • Click Build Phases
  • Reveal Compile Sources.
  • At the bottom, click the plus sign and then enter .m into the search bar. If any files are listed there, select them and add them.

I've had problems with new classes not appearing here in the past.

How to get your custom content drawn in Interface Builder?

As I understand it at the moment (prior to Xcode 6 Beta 3), @IBDesignable will only work from a view declared in a separate framework target.
However, I also struggled to add it because I had no "plus" button as described in various links (because the Hide Project & Target Lists arrow option was toggled off).

So, select your current project target, then just use the xcode menu options:
Editor > Add target...
Then select
Framework & Library > Cocoa Touch Framework etc.

By the way, to test @IBDesignable, this tutorial worked perfectly as a starting point:
http://www.weheartswift.com/make-awesome-ui-components-ios-8-using-swift-xcode-6/

One small but important thing to note in that tutorial (if you follow it onscreen instead of following on to its full github code listing) is that your view class must be prepended/decorated with @IBDesignable, e.g.
class CustomView : UIView {...}
should be
@IBDesignable class CustomView : UIView {...}

Unknown class MyClass in Interface Builder file error at runtime

Despite the "Unknown class MyClass in Interface Builder file." error printed at runtime, this issue has nothing to do with Interface Builder, but rather with the linker, which is not linking a class because no code uses it directly.

When the .nib data (compiled from the .xib) is loaded at runtime, MyClass is referenced using a string, but the linker doesn't analyze code functionality, just code existence, so it doesn't know that. Since no other source files references that class, the linker optimizes it out of existence when making the executable. So when Apple's code tries to load such a class, it can't find the code associated with it, and prints the warning.

By default, Objective-C targets will have -all_load -ObjC flags set by default, which will keep all of the symbols. But I had started with a C++ target, and didn't have that. Nevertheless, I found a way around this, which keeps the linker aggressive.

The hack I was originally using was to add an empty static routine like:

+(void)_keepAtLinkTime;

which does nothing, but that I would call once, such as:

int main( int argc, char** argv )
{
[MyClass _keepAtLinkTime];
// Your code.
}

This would force the linker to keep the whole class, and the error disappears.

As jlstrecker pointed out in the comments, we do not really need to add a _keepAtLinkTime method. Simply calling an existing one, such as:

   [MyClass class];

does the trick (as long as you derive from an NSObject).

Of course, you can call this in any location of your code. I guess it could even be in unreachable code. The idea is to fool the linker into thinking that MyClass is used somewhere so that it isn't so aggressive in optimizing it out.

Xcode 6.3.2 & Swift 1.2

Swift definition of view. Be sure to override init(coder aDecoder: NSCoder). Objective-C definition of view controller. And, a nib in a pear tree.

Add Module Name to Nib details inspector where you pick your class.

UIView custom xib doesn't show up

nibs cannot be nested within the structure.

Instead of:

UIViewController -> UIView -> nibs..

It should be:

UIViewController -> Container View -> UIView with nibs.

Xcode 6 Bug: Unknown class in Interface Builder file

I resolved this issue as I was typing the question. I figured I'd answer my question and leave it here for anyone else who may face this issue when using Xcode 6 beta 4.

To resolve this issue, you need to select each of your custom class objects in Storyboard (this includes any custom views, even the custom view controllers themselves).

Then with those objects selected, open the identity inspector and under "Custom Class" you should see the Module option. Finally:

  • Click inside the Module text box, and press enter.
  • Or (update 2022), check the "Inherit Module From Target" option.

That's it! The current module for all of my custom objects must have been internally incorrectly set somehow in Xcode 6 beta 4. But there was no visual indication of this in the inspector.

Note that if pressing enter inside the Module text box doesn't work, try selecting the arrow to the right and manually select your current module, then clear the text box and press enter. You can also try pressing enter inside the class text box (although this usually is to resolve a different issue).

Here is an image to make things more clear:
Sample Image



Related Topics



Leave a reply



Submit