I'm attempting to implement the target-action pattern in a custom UIControl
. Here's the setup:
// Inside custom UIControl class
- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
...
// UIControl method to update targets when values change
[self sendActionsForControlEvents:UIControlEventValueChanged];
return YES;
}
- (void)valueChanged:(id)control
{
NSLog(@"Value changed");
}
I have a simple view controller that initializes an instance of my custom UIControl and registers as a target for when values change:
// Inside view controller
@implementation HKViewController
{
HKCustomControl *_customControl;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_customControl = [[HKCustomControl alloc]];
[self.view addSubview:_customControl];
[_customControl addTarget:self
action:@selector(valueChanged:)
forControlEvents:UIControlEventValueChanged];
}
The error I get is: ''NSInvalidArgumentException', reason: '-[HKViewController valueChanged:]: unrecognized selector sent to instance 0x16d95b20'
I have added - (void)valueChange:(id)control
to the .h
file for my custom control as well.
I have read a number of posts already about similar errors but none specific to this pattern. I could use a second pair of eyes to see where I'm going wrong.