Reputation: 4025
I want to perform additional tasks whenever the image of a UIImageView is set. I'm attempting to define a custom setter method, but having no luck.
h:
@property (nonatomic, strong, setter = setImage:) UIImage *image;
m:
- (void)setImage:(UIImage *)image {
self.image = image;
// additional tasks here
}
This obviously incurs an infinite loop. How do I do this?
Upvotes: 3
Views: 1033
Reputation: 20720
Obviously you are triggering setter with self.image = image;
use _image = image;
to avoid that.
Upvotes: 0
Reputation: 1586
Instead of
self.image = image;
do
[super setImage:image];
Also, you don't need to specify the setter since that is the default.
Upvotes: 5