我在UITableViewCell上使用UISwitch。当我按下保存按钮时,我想获得UISwitch值。我怎么才能得到它?我的代码如下:
- (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]);
}
答案 0 :(得分:1)
- (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]);
}