문제

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]);
}
도움이 되었습니까?

해결책

- (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]);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top