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]);
}
Était-ce utile?

La 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]);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top