0

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?

4

1 回答 1

0

将您的函数绑定到事件: UIControlEventValueChanged 到此函数

-(IBAction)_clickswitchlowlight:(id)sender
    {

    if(switchControll.on){

        [[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_lowlighton object:nil];
    }
    else{

       [[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_lowlightoff object:nil];

    }
}
于 2012-04-27T11:11:46.607 回答