views:

831

answers:

2

I have a very simple app that processes touches on a UIImageView derived view.

The view has an array of rectangle coordinates that act as buttons.

Since this is a simple app I handle all the touch events right in my UIImageView derived class.

I need to init the array of image coordinates which is an instance variable.

I tried overriding several methods including init, but none of the ones I tried are called.

What is the proper method to override to initialize instance variables in a UIImageView derived class?

Thanks!

+2  A: 

There are several init functions (initWithFrame, initWithCoder, etc), and which one is called will depend on how you are loading the image view. If you are loading it from a NIB, try initWithCoder.

Alternatively, you could always use the viewDidLoad method in your controller, and have it call a custom initialization method on the view. I wouldn't recommend that though in this case unless you really had to do it that way.

Eric Petroelje
+1  A: 

If your class is loaded as part of a nib, you can use AwakeFromNib: to initialize variables when the nib file is loaded.

Mark Bessey