If you hook up the IBAction
to the switch, you don't need to get the UITableViewCell
to check for the switch's value. You can use the sender parameter from the IBAction
. Hence:
- (IBAction)toggleSwitch:(id)sender {
UISwitch *switch = (UISwitch *)sender;
if (switch.on)
{
NSLog(@"On");
}
}
If you need to find the indexPath
at which the UISwitch
is shown, you can add the following:
CGPoint pointInTable = [switch convertPoint:switch.bounds.origin toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:pointInTable];