drawRect not being called in my subclass of UIImageView

It’ll only get called if the view is visible, and dirty. Maybe the problem is in the code that creates the view, or in your Nib, if that’s how you’re creating it?

You’ll also sometimes see breakpoints failing to get set properly if you’re trying to debug a “Release” build.

I somehow missed the first time that you’re subclassing UIImageView. From the docs:

Special Considerations

The UIImageView class is optimized to
draw its images to the display.
UIImageView will not call drawRect: in a
subclass. If your subclass needs
custom drawing code, it is recommended
you use UIView as the base class.

So there you have it. Given how easy it is to draw an image into your view using [UIImage drawInRect:], or by using CALayer, there’s probably no good reason to subclass UIImageView anyway.

Leave a Comment