0
votes

I have 2 classes, ClassA and ClassB

ClassA calls ClassB's method : - (void)someMethod:(id)sender

in the above method, I need to grab the sender from ClassB (the sender is a subclass of UIView that has a UIButton on it) and update the button image using something along the lines of [sender updateButtonImageWithImage:image]

(the UIView subclass has the method: - (void)updateButtonImageWithImage:(UIImage *) )

but whenever I call this from ClassB the app crashes with [UIButton updateButtonImageWithImage:] unrecognized selector blah blah blah.

what am I doing wrong?

1

1 Answers

2
votes

the sender is a subclass of UIView that has a UIButton on it

This is incorrect—if the button is what’s triggering -someMethod:, then the button, not the view containing it, is the sender that gets passed into -someMethod:. The easiest way to do this would be to grab the button’s superview (which should be your view subclass), then call your -updateButtonImageWithImage: on that:

[(MyViewSubclass *)[sender superview] updateButtonImageWithImage:image];