Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There are two pages
home.m
settings.m
 
I'm having a switch button in setting.m page and i'm storing it in NSManagedObjectContext.
 
And i have read this value in home.m page like this. I'm having an another switch button in home.m page to see whether it reflects or not.
C#
- (void) viewWillAppear:(BOOL)animated {

    if ([[self.settings objectForKey:@"mem"]boolValue])
        self->Mode.on = YES;
    else
        self->Mode.on = NO;


 
Whenever i save the switch value in settings.m page it will reflect on home.m page.
Now what i need is " how do i find that the value is changed or not? "
 
Really i'm stucked in this for past two days. help me to complete this. I have miles to go in my project.
Thanks in Advance.
Posted

There are different ways. You can declare an outlet to access the uiswitch via its on property and set it.

Another way to work work via the Interface Builder and handle the event "Value changed".
 
Share this answer
 
C#
- (void)viewDidLoad
{
    [super viewDidLoad];
    if ([[self.settings objectForKey:@"mem"]boolValue])
        self->mySwitch.on = YES;
    else
        self->mySwitch.on = NO;
    [mySwitch addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:mySwitch];
}

- (void)changeSwitch:(id)sender{
    if([sender isOn]){
        NSLog(@"Switch is ON");
    } else{
        NSLog(@"Switch is OFF");
    }
}


I'm getting the changes in mySwitch when I click it but it does not calls the changeSwitch: method automatically when the value changes in core data.

I'm looking for this Please help me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900