6
votes

This shouldn't be this confusing. I have a custom UIView with a bunch on controls on it. UILabels, buttons, etc. I've created this Nib using Interface Builder. I want to be able to position this custom uiview on another UIView using the interface builder.

How do I link my UIView custom class, to the nib? initWithCoder gets called, but I want this class to get loaded from the nib.

Thanks

4
Have you found an acceptable answer? Please mark it, thanks.JoePasq
@JoePasq do you see ANY valid answers here?Dan Rosenstark
i actually never got this working unfortunatelyNader

4 Answers

3
votes

For this to work, you have to create a plug-in for Interface Builder that uses your custom control's class. As soon as you create and install your plug-in, you will be able to add by drag and drop, instances of your view onto another window or view in Interface Builder. To learn about creating IB Plugins, see the Interface Builder Plug-In Programming Guide and the chapter on creating your own IB Palette controls from Aaron Hillegass's book, Cocoa Programming for Mac OS X.

Here is the link to the original author of the accepted answer to a similar question.

2
votes

You only need to make a plugin if you want the custom view to draw correctly in the nib you are using it. You can make a custom control and then have it show as a blank rectangle until instantiated during run right now.

How do I get a view in Interface Builder to load a custom view in another nib?

0
votes

You can insert a UIViewController object using Interface Builder, and then set the UIViewController's "Nib name" property. I don't know if this messes up your model, but I think it's the only way to do what you're trying to do.

0
votes

In IB bring up the Identity Inspector tool (Command-4) then select your custom view and in the Class pop-up choose the name of your custom class instead of generic UIView. You may want to connect it to an ivar as well. In your ViewController declare an instance of your custom class with an IBOutlet in front of it. Then go back and bring up the Connections Inspector and connect your view to the ivar by click-dragging from the custom-view's referencing outlet to the File's Owner (which should be an instance of your ViewController) and choosing the ivar name.

When your NIB is loaded it should be creating an object of that type and connecting it to that variable.