Sergey Grishchev
Sergey Grishchev

Reputation: 12051

AddTarget to UIView

I'm writing my own custom control which is implemented through UIView.

And when I initialize it, I would like to add a custom target to it like this:

[myControl addTarget:self action:@selector(turnOn) forControlEvents:UIControlEventValueChanged];

I do this so when I change something on my UIView, it would trigger that sort of method in its parent control. I am aware that there's a delegate for such purposes, but I was wondering if it is possible to do without it.

How do you do this sort of thing in Objective-C? Thanks in advance!

Upvotes: 1

Views: 1144

Answers (1)

Dan F
Dan F

Reputation: 17732

If you instead subclass UIContol you can invoke

- (void)sendActionsForControlEvents:(UIControlEvents)controlEvents

from within your subclass, and that will trigger the action

Upvotes: 1

Related Questions