Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
- }
- switch (indexPath.row) {
- case 2:
- cell.textLabel.text = @"Weather";
- switchControl = [[UISwitch alloc] initWithFrame:CGRectZero];
- cell.accessoryView = switchControl;
- [self.switchControl setOn:YES animated:NO];
- [self.switchControl addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
- [switchControl release];
- break;
- default:
- break;
- }
- cell.textLabel.text = [settings objectAtIndex:indexPath.row];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- return cell;
- }
- -(void)switchChanged:(id)sender
- {
- app= (StopSnoozeAppDelegate*)[[UIApplication sharedApplication]delegate];
- NSString *value;
- userdefaults = [NSUserDefaults standardUserDefaults];
- if(!switchControl.on){
- value = @"OFF";
- [userdefaults setObject:value forKey:@"stateOfSwitch"];
- }
- [userdefaults setObject:value forKey:@"stateOfSwitch"];
- [userdefaults synchronize];
- }
- - (void)viewWillAppear:(BOOL)animated {
- NSString *_value= [[NSUserDefaults standardUserDefaults] stringForKey:@"stateOfSwitch"];
- if([_value compare:@"ON"] == NSOrderedSame){
- [self.switchControl setEnabled:YES];
- }
- else {
- [self.switchControl setEnabled:NO];
- }
- [super viewWillAppear:animated];
- }
- [yourSwitch setOn:NO animated:YES];
- [yourSwitch setOn:YES animated:YES];
- switchControl = [[UISwitch alloc] initWithFrame:CGRectZero];
- cell.accessoryView = switchControl;
- [self.switchControl setOn:YES animated:NO];
- [self.switchControl addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
- [switchControl release];
- self.switchControl = [[UISwitch alloc] initWithFrame:CGRectZero];
- cell.accessoryView = switchControl;
- [self.switchControl setOn:YES animated:NO];
- [self.switchControl addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
- NSString *_value= [[NSUserDefaults standardUserDefaults] stringForKey:@"stateOfSwitch"];
- if([_value compare:@"ON"] == NSOrderedSame) {
- [self.switchControl setEnabled:YES];
- } else {
- [self.switchControl setEnabled:NO];
- }
- switchOutlet.on = YES;
- switchOutlet.on = NO;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement