redribben

switches

Jan 27th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //in the method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2.  
  3. cell.cellSwitch.tag = indexPath.row;
  4. [cell.cellSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
  5.  
  6.  
  7. //and the method responsible for the actions that Im going to implement:
  8.  
  9. -(void)switchChanged:(id)sender {
  10.     UISwitch *senderSwitch = (UISwitch *)sender;
  11.     if (senderSwitch.tag == 0) {
  12.         if (senderSwitch.on == 1) {
  13.             NSLog(@"Switch 1 ON");
  14.         }
  15.         else if (senderSwitch.on == 0) {
  16.             NSLog(@"Switch 1 OFF");
  17.         }
  18.     }
  19.     if (senderSwitch.tag == 1) {
  20.         if (senderSwitch.on == 1) {
  21.             NSLog(@"Switch 2 ON");
  22.         }
  23.         else if (senderSwitch.on == 0) {
  24.             NSLog(@"Switch 2 OFF");
  25.         }
  26.     }
  27.     if (senderSwitch.tag == 2) {
  28.         if (senderSwitch.on == 1) {
  29.             NSLog(@"Switch 3 ON");
  30.         }
  31.         else if (senderSwitch.on == 0) {
  32.             NSLog(@"Switch 3 OFF");
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment