views:

1479

answers:

3

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

A: 

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.

Kenny Winker
Hi Kenny, thanks for the quick response. I just tried that. I added a UIViewController to my main view, set it's nib name to custom sub view's nib, and connected the uiviewcontroller's view property to the custom view in interface builder. Same thing. It's just not showing up. initWithCoder is getting called on the custom view, but nothing is showing up.
Nader
A: 

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.

Ramin
+1  A: 

I was having this same problem.

Ben Collins