I've subclasses UIControl and in it I am sending:
[self sendActionsForControlEvents:UIControlEventValueChanged];
When I create an instance of the object, I add a target as follows:
[starView addTarget:self action:@selector(starRatingChanged:) forControlEvents:UIControlEventValueChanged];
The view shows up fine, and without the target being there the functionality works well. But with adding the target, it crashes. Any ideas why?
My class is declared with:
@interface RMStarRating : UIControl {...}
For what it is worth, I set up my view in - (void)layoutSubviews
. Is there another method that I need to subclass in order for the targets to be saved properly or for the targets to be sent the right actions? I thought UIControl handled saving the targets and actions for you.
UPDATE: trying to provide more information
I set the object up as follows:
RMStarRating *starView = [[RMStarRating alloc] initWithFrame:CGRectMake(10, 70, 23*5, 30)];
[starView addTarget:self action:@selector(starRatingChanged:) forControlEvents:UIControlEventValueChanged];
....
[self.view addSubview:starView];
My sendAction, according to Jordan's suggestion:
- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event {
NSLog(@"send action");
[super sendAction:action to:target forEvent:event];
}
My function that calls sendActionsForControlEvents:
- (void)updateValue:(UITouch *)touch {
....
NSLog(@"sendActionsForControlEvents");
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
And the function that should be called (and it is in the header too):
- (void)starRatingChanged:(id)sender {
NSLog(@"star rating changed");
}
And the log just spits out:
2010-10-22 09:45:41.348 MyApp[72164:207] sendActionsForControlEvents
2010-10-22 09:45:41.350 MyApp[72164:207] send action
The debugger has: