Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making custom UIView with two UIButtons for UITableViewCell accessoryView member causes unrecognized selector sent to instance error

I'm trying to make a view with two buttons for a table cell accessory view to do two (obviously) different things to the object at that cell index. I made two basic rounded rect UIButtons with a selector in the RootViewController (where the UITableView resides). Here is the code I use to initialize this view in a cell that is found in the cellForRowAtIndexPath method:

UIButton* minus = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; [minus setFrame:CGRectMake(0, 0, 30, 30)]; [minus setTitle:@"-" forState:UIControlStateNormal]; [minus addTarget:self action:@selector(subtractOne:event:) forControlEvents:UIControlEventTouchDown]; UIButton* plus = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; [plus setFrame:CGRectMake(30, 0, 30, 30)]; [plus setTitle:@"+" forState:UIControlStateNormal]; [plus addTarget:self action:@selector(addOne:event:) forControlEvents:UIControlEventTouchDown]; UIView* customAccessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)]; [customAccessory addSubview:minus]; [customAccessory addSubview:plus]; cell.accessoryView = customAccessory; [customAccessory release];

And the two methods they call are defined:

- (void)subtractOne:(id)sender forEvent:(UIEvent *)event; - (void)addOne:(id)sender forEvent:(UIEvent *)event;

Any ideas why this would throw unrecognized sender sent to instance "RootViewController"?

Here is the full error:

2011-03-20 20:34:35.493 MyApp[23262:207] -[RootViewController subtractOne:event:]: unrecognized selector sent to instance 0x573c350 2011-03-20 20:34:35.496 MyApp[23262:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RootViewController subtractOne:event:]: unrecognized selector sent to instance 0x573c350'

like image 578
Kristian K Avatar asked Dec 07 '25 09:12

Kristian K


1 Answers

Realized my own stupid mistake: Was trying to call on subtractOne:event: when I wrote method for subtractOne:forEvent:

like image 50
Kristian K Avatar answered Dec 10 '25 00:12

Kristian K