views:

32

answers:

1

Hello all,

in my app i have a switch in the flipsideview when i set it to on all work properly then i touch Done to return to the main view, now when i touch again the info button it appear off till now no problem but if i touch Done button (without touch the switch) it will called the function with off statement my question is how to check if the switch (on FlipsideView) is on let it on where i should write my code maybe i'll do it by myself but where to write the code

A: 

You could store the state as a member variable, then update the UI in viewWillAppear:animated:. For example, in FlipsideViewController.h file, declare a member variable called switchIsOn:

@interface FlipsideViewController : UIViewController {
    BOOL switchIsOn;
    // Other member variables here
}

@property (nonatomic) BOOL switchIsOn;

Then in FlipsideViewController.m:

@synthesize switchIsOn;

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.switch setOn:self.switchIsOn animated:NO];
}

You can set the value of self.switchIsOn in response to the switch being toggled. e.g. create a method like this:

-(IBAction)handleSwitch:(id)sender {
    self.switchIsOn = self.switch.on;
}

and then bind that method to the switch's Value Changed event.

Hope this helps.

Simon Whitaker
hello thanks for the answer but what the type of storedvalue i got an error: request for member 'storedValue' in something not a structure or union" some help plz
Bobj-C
You need to declare the property too. I've updated my answer to show that bit.
Simon Whitaker
ok now when i pressed the info button the switch is off click to on done all work properly, but if click the info second time it is off again
Bobj-C