2012-04-27 3 views
0

メインページのイメージを変更するために私の設定ページに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通知を取得し、私はいずれにも欠けている...最初の通知を取得できませんでした私のコード?ありがとうございます。 イベントへのあなたの関数のバインド

+0

なぜあなたはスイッチの状態を変更しますにUIControlEventValueChanged? [switchControll setOn:YES animated:YES]; ?? –

+0

@Ubersoldatがオンかどうかをチェックするのはエラーですか? – stackiphone

+0

いいえ、すでに "ON"の状態で "ON"に設定しようとしています。どうして? –

答えて

0

:この機能

-(IBAction)_clickswitchlowlight:(id)sender 
    { 

    if(switchControll.on){ 

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

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

    } 
} 
+0

メインページのlowlightoffにアラートビューを表示します。スイッチのオンまたはオフにアラートが表示されます.-(void)clicklowlightoff :(NSNotification *)notif { [[self multiPageView] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@ "bglowlight @ 2x"]]]; が//ここで私は }はイベントにあなたの関数をバインド – stackiphone

+0

アラートビューを置く:?この関数にUIControlEventValueChangedそれは感謝 – stackiphone

+0

ドラッグを何を意味していると、この関数にuicontroleventvaluechangedリンカをドロップすると、リンク解除他人を –

関連する問題