2012-04-27 4 views
0

내 설정 페이지에 UISwitchController가있어 메인 page.so에서 이미지를 바꿀 수 있습니다. 페이지를 먹는 페이지의 알림을 기본 페이지에 넣습니다. 그러나 매번 활성화되는 알림, 설정 페이지 전환 코드보기 내 주요 page.h..i이NSnotifiaction 의문의 여지가

-(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

아니요, 이미 "켜짐"상태에서 "켜기"로 설정하려고합니다. 왜? –

답변

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

경고보기 }를 넣어 // 여기에 이 : 그것은 감사 – stackiphone

+0

드래그 무엇을이 함수에 UIControlEventValueChanged을 의미합니까이 기능에 uicontroleventvaluechanged 링커를 떨어 뜨리고 난 정말 미안 해요, 난 다시 'didn를하고 다른 사람에게 –

관련 문제