メインページのイメージを変更するために私の設定ページにUISwitchコントローラがあります。私はメインページにページを食べるからの通知を入れました。しかし毎回アクティブな1つの通知、私の設定ページのスイッチコードの外観私のメインpage.h..iでこのNSnotifiaction doubt
-(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];
}
}
のように私はこの
NSString * const NOTIF_lowlighton = @"lowlighton";
NSString * const NOTIF_lowlightoff = @"lowlightoff";
を書く
メインページの実装上記の.mで
extern NSString * const NOTIF_lowlighton;
extern NSString * const NOTIF_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:@"[email protected]"]]];
}
を変更するため、このコードを書く私はclicklowlightoff通知を取得し、私はいずれにも欠けている...最初の通知を取得できませんでした私のコード?ありがとうございます。 イベントへのあなたの関数のバインド
なぜあなたはスイッチの状態を変更しますにUIControlEventValueChanged? [switchControll setOn:YES animated:YES]; ?? –
@Ubersoldatがオンかどうかをチェックするのはエラーですか? – stackiphone
いいえ、すでに "ON"の状態で "ON"に設定しようとしています。どうして? –