Guest User

Untitled

a guest
Jun 27th, 2019
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2.  
  3. static NSString *CellIdentifier = @"Cell";
  4.  
  5. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  6. if (cell == nil) {
  7. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  8. }
  9.  
  10. switch (indexPath.row) {
  11.  
  12. case 2:
  13. cell.textLabel.text = @"Weather";
  14. switchControl = [[UISwitch alloc] initWithFrame:CGRectZero];
  15. cell.accessoryView = switchControl;
  16.  
  17. [self.switchControl setOn:YES animated:NO];
  18. [self.switchControl addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
  19. [switchControl release];
  20. break;
  21.  
  22.  
  23. default:
  24. break;
  25. }
  26. cell.textLabel.text = [settings objectAtIndex:indexPath.row];
  27. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  28.  
  29.  
  30.  
  31. return cell;
  32. }
  33.  
  34.  
  35.  
  36. -(void)switchChanged:(id)sender
  37. {
  38.  
  39. app= (StopSnoozeAppDelegate*)[[UIApplication sharedApplication]delegate];
  40.  
  41. NSString *value;
  42. userdefaults = [NSUserDefaults standardUserDefaults];
  43. if(!switchControl.on){
  44. value = @"OFF";
  45. [userdefaults setObject:value forKey:@"stateOfSwitch"];
  46. }
  47. [userdefaults setObject:value forKey:@"stateOfSwitch"];
  48. [userdefaults synchronize];
  49.  
  50. }
  51.  
  52.  
  53. - (void)viewWillAppear:(BOOL)animated {
  54. NSString *_value= [[NSUserDefaults standardUserDefaults] stringForKey:@"stateOfSwitch"];
  55.  
  56. if([_value compare:@"ON"] == NSOrderedSame){
  57. [self.switchControl setEnabled:YES];
  58. }
  59. else {
  60. [self.switchControl setEnabled:NO];
  61. }
  62. [super viewWillAppear:animated];
  63. }
  64.  
  65. [yourSwitch setOn:NO animated:YES];
  66.  
  67. [yourSwitch setOn:YES animated:YES];
  68.  
  69. switchControl = [[UISwitch alloc] initWithFrame:CGRectZero];
  70. cell.accessoryView = switchControl;
  71.  
  72. [self.switchControl setOn:YES animated:NO];
  73. [self.switchControl addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
  74. [switchControl release];
  75.  
  76. self.switchControl = [[UISwitch alloc] initWithFrame:CGRectZero];
  77. cell.accessoryView = switchControl;
  78.  
  79. [self.switchControl setOn:YES animated:NO];
  80. [self.switchControl addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
  81.  
  82. NSString *_value= [[NSUserDefaults standardUserDefaults] stringForKey:@"stateOfSwitch"];
  83.  
  84. if([_value compare:@"ON"] == NSOrderedSame) {
  85. [self.switchControl setEnabled:YES];
  86. } else {
  87. [self.switchControl setEnabled:NO];
  88. }
  89.  
  90. switchOutlet.on = YES;
  91.  
  92. switchOutlet.on = NO;
RAW Paste Data