メインページの画像をUISwitchcontroller
変更する設定ページがあります。そこで、設定ページからメインページに通知を入れました。ただし、毎回アクティブにする通知は 1 つだけです。設定ページの切り替えコードは次のようになります。
-(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];
}
}
私のメインページで.h..私はこのコードを書きます:
extern NSString * const NOTIF_lowlighton;
extern NSString * const NOTIF_lowlightoff;
メインページの実装の上の .m に、次のように記述します。
NSString * const NOTIF_lowlighton = @"lowlighton";
NSString * const NOTIF_lowlightoff = @"lowlightoff";
私はこのviewwillappear
コードを書きます:
- (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];
}
次に、画像を変更するためのこのコード:
- (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"]]];
}
私は通知を受け取るだけでclicklowlightoff
、最初の通知を受け取りませんでした...私のコードに欠けているものはありますか?