views:

213

answers:

2

If I subclassed a UIView from interface builder, and now need an instance of that subclass in my app controller, how would I get that reference (To the subclass and not the UIView)?

A: 

Make an IBOutlet in your app controller and hook it up in InterfaceBuilder.

That's how you access it from your code.

Rhythmic Fistman
+2  A: 

One way to do this is the following:

  1. Drag a UIView object from the Library within Interface Builder (IB) to your Nib window (the window that shows all the objects in the Nib). Change the class from UIView to your new subclass in the object inspector (Shift-Control-i).
  2. Create a outlet in your app controller header file:

    IBOutlet MySubViewClass *myView;

  3. Connect the myView outlet with the object you have created in step in IB. You can do this by right-click-and-drag the app controller object to the view object and choosing the myView outlet in the window that pops up.

Diederik Hoogenboom