I’, have a UITableView with UISwitch in some cells.
I want to capture events, but it crashes when I try to add the indexPath.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Create cell with all data
UISwitch *switchview = [[UISwitch alloc] initWithFrame:CGRectZero];
cell.accessoryView = switchview;
[switchview addTarget:self action:@selector(updateSwitchAtIndexPath) forControlEvents:UIControlEventTouchUpInside];
}
- (void)updateSwitchAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
UISwitch *switchView = (UISwitch *)cell.accessoryView;
if ([switchView isOn]) {
NSLog(@"ON");
} else {
NSLog(@"OFF");
}
}
It crashes, I think because I’m not adding the indexPath parameter, but I can’t get how to set it.
-[ParkingData updateSwitchAtIndexPath]: unrecognized selector sent to instance 0x7b88eb0
Thanks!
UPDATE