views:

29

answers:

2

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:

debugger picture

A: 

Have you tried implementing

- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event

instead? A good example is located here:

http://stackoverflow.com/questions/1241624/can-i-override-the-uicontroleventtouchupinside-for-a-uisegmentedcontrol

Jordan
Thanks for that link. Unfortunately passing that onto super didn't work. sendAction:to:forEvent did gets called, but still crashes.
RyanJM
Then you have another problem. Post the crash log, at least, and the code with sendAction, and setup.
Jordan
I've posted more information, I hope that helps. By the crash log you mean the development log right?
RyanJM
Whats the error when it crashes (debugger log)
Jordan
I added an image of what the debugger has.
RyanJM
@RyanJM Try changing the event to UIControlEventAllEvents and see if it fires. I created a template project, added RMStarRating, added target and my starRatingChanged event fired. Without the sendAction.
Jordan
A: 

Ok, I figured out what it was. I was releasing my parent class too soon, so there was no object for the message to be sent back to, even though it was showing on screen.

And I ended up not needing the sendAction:to:forEvent.

Jordan, thanks you for your help.

RyanJM
lol - see, it helps if you post all of the code, instead of snippets. Hard to tell what's really going on. Glad you figured it out.
Jordan