0

I need to create a small UITableView with cells that each contain a UISwitch.

For example I want to have two UISwitchs, "A" and "B", at rows 0 and 1, so that if I set switch "A" to On, switch "B" will go to the Off position.

How I can do that simply?

Thanks.

jscs
  • 63,694
  • 13
  • 151
  • 195
Maxime
  • 3,167
  • 7
  • 26
  • 33

2 Answers2

0

You need to create custom table view cells. Look here for UISwitch class reference.

Use this to detect the changes in switch.

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

Similar post is found here

Community
  • 1
  • 1
  • Yes,at understand but it's not answer my qusetion... I have already customs table view cells but when I change the value (switch) of the first cell it nee to change the value of the second cell too...I just need to understand the logic steps... – Maxime May 12 '11 at 17:30
0

First tag the switches:

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

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

Then implement the actionSwitch selector:

-(void)actionSwitch {

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

        [switchB setOn:NO animated:YES];
    }
}
Ruben Marin
  • 1,639
  • 14
  • 24