I built the cell with Interface Builder. I load the cells like this:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"MassCircleNGTableCell" owner: self options: nil];
cell = circleNGCell;
self.circleNGCell = nil;
}
UISwitch *s = (UISwitch*)[cell.contentView viewWithTag: 20];
UILabel *label = (UILabel*)[cell.contentView viewWithTag:19];
label.text = @"some useful text";
And that part works, I get my table with custom cells. But, although I can set the initial state, I don't know how to respond to the user flipping the switch! I tried this:
[leftSwitch addTarget:self action:@selector(setCircle) forControlEvents:UIControlEventTouchUpInside];
But the app crashes with "[MassCircleNGViewController setCircle]: unrecognized selector sent to instance 0xdd024b0'"
Any ideas out there?
[Added Later (as requested)]:
// implementation of [MassCircleNGViewController setCircle] really just a stub here
- (IBAction) setCircle: (id) sender {
NSLog(@"setCircle sender == %@", (UISwitch*)sender);
}
The real problem was how I was trying to add the target. Need that colon after the selector name in the argument list!
[leftSwitch addTarget:self action:@selector(setCircle:) forControlEvents:UIControlEventValueChanged];