سؤال

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