Question

I'm using UISwitch on UITableViewCell. When I the push save button, I want to get UISwitch value. How can I get it? My code listed below:

- (void)save:(id)sender
{
    UITableViewCell *commentCell = [self.tableView dequeueReusableCellWithIdentifier:@"CustomInfoCell" forIndexPath: [NSIndexPath indexPathForRow:0 inSection:0]];
    UISwitch* commentSwitch = (UISwitch*)[commentCell viewWithTag:2];

    NSLog(@"%@", [NSNumber numberWithBool:commentSwitch.on]);
}
Was it helpful?

Solution

- (void)save:(id)sender
{
    UITableViewCell *commentCell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    UISwitch* commentSwitch = (UISwitch*)[commentCell viewWithTag:2];

    NSLog(@"%@", [NSNumber numberWithBool:commentSwitch.on]);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top