0

我需要创建一个小UITableView的单元格,每个单元格都包含一个UISwitch.

例如,我想在UISwitch第 0 行和第 1 行有两个 s,“A”和“B”,这样如果我将开关“A”设置为 On,则开关“B”将转到 Off 位置。

我怎么能简单地做到这一点?

谢谢。

4

2 回答 2

0

您需要创建自定义表格视图单元格。在此处查找UISwitch类参考。

使用它来检测开关的变化。

[switch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];

在这里可以找到类似的帖子

于 2011-05-12T17:23:47.090 回答
0

首先标记开关:

UISwitch *switchA = [[UISwitch alloc] init];
[switchA addTarget:self action:@selector(actionSwitch) forControlEvents:UIControlEventValueChanged];
switchA.tag = 1;

UISwitch *switchB = [[UISwitch alloc] init];
switchB.tag = 2;

然后实现actionSwitch选择器:

-(void)actionSwitch {

    UISwitch *switchA = (UISwitch)[self.view viewWithTag:1];
    UISwitch *switchB = (UISwitch)[self.view viewWithTag:2];
    if([switchA isOn]) {

        [switchB setOn:NO animated:YES];
    }
}
于 2011-05-12T17:30:59.490 回答