I have a UITableView with one UISwitch for row. To do it:
UISwitch *switchController = [[UISwitch alloc] initWithFrame:CGRectZero];
if([valor isEqualToString:@"true"])
[switchController setOn:YES animated:YES];
else
[switchController setOn:NO animated:YES];
switchController.tag = row;
[switchController addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = switchController;
[switchController release];
Ok, i want exclusive row, when i touch one UISwitch i need put all others UISwitch in OFF.
But i can´t do it…Someone can help me?
Thanks friends.
-(void) switchChanged:(id)sender{
UISwitch *switchController = sender;
}
One simple approach could be like this.
You want that user can switch on only one row at a time. For this you will need to keep track of two things first the switches(we can access it via cell’s accessory view) and second the switch which is on.(for this suppose we use tag property).
I have created a sample app with following code:(I am taking number of rows as constant to 10)
Code
SwitchTableController.h
SwitchTableController.m code