I have a UISwitchcontroller
in my setting page to change the image in main page. So I put a notification from setting page to main page. But only one notification I active every time, my setting page switch code look like this:
-(IBAction)_clickswitchlowlight:(id)sender
{
if(switchControll.on){
[switchControll setOn:YES animated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_lowlighton object:nil];
}
else{
[switchControll setOn:NO animated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_lowlightoff object:nil];
}
}
In my main page.h..I write this code:
extern NSString * const NOTIF_lowlighton;
extern NSString * const NOTIF_lowlightoff;
In .m above the implementation of main page I write this:
NSString * const NOTIF_lowlighton = @"lowlighton";
NSString * const NOTIF_lowlightoff = @"lowlightoff";
In viewwillappear
I write this code:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clicklowlighton:) name:@"lowlighton" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clicklowlightoff:) name:@"lowlightoff" object:nil];
}
Then this code for changing the image:
- (void)clicklowlighton:(NSNotification *)notif
{
[[self multiPageView] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bgipad"]]];
}
- (void)clicklowlightoff:(NSNotification *)notif
{
[[self multiPageView] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bglowlight@2x"]]];
}
I only get the clicklowlightoff
notification, I didn't get the first notification...any missing in my code?