//in the method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
cell.cellSwitch.tag = indexPath.row;
[cell.cellSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
//and the method responsible for the actions that Im going to implement:
-(void)switchChanged:(id)sender {
UISwitch *senderSwitch = (UISwitch *)sender;
if (senderSwitch.tag == 0) {
if (senderSwitch.on == 1) {
NSLog(@"Switch 1 ON");
}
else if (senderSwitch.on == 0) {
NSLog(@"Switch 1 OFF");
}
}
if (senderSwitch.tag == 1) {
if (senderSwitch.on == 1) {
NSLog(@"Switch 2 ON");
}
else if (senderSwitch.on == 0) {
NSLog(@"Switch 2 OFF");
}
}
if (senderSwitch.tag == 2) {
if (senderSwitch.on == 1) {
NSLog(@"Switch 3 ON");
}
else if (senderSwitch.on == 0) {
NSLog(@"Switch 3 OFF");
}
}
}
Comments