2014-02-21 1 views
0

이 코드에 어떤 문제가 ...NSNotificationCenter 객체 UILabel의

[[NSNotificationCenter defaultCenter] addObserver : 자기 선택기 : @ 선택기 (MySubViewNotification : 이름 : @ "MySubViewNotification"개체 : 무기 호]

-(void)MySubViewNotification:(UILabel*)GenericLabel 
{ 

    GenericLabel.textColor = [UIColor whiteColor]; ---- Error ---- 
    GenericLabel.text = @"cwxcwxc"; ---- Error ---- 

    NSLog(@"%@", GenericLabel); 
} 

NSLog. 

NSConcreteNotification 0x1759c6c0 {name = MySubViewNotification; object = <UILabel: 0x175aace0; frame = (175 5; 62 15); text = '1.35'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x175aad80>>} 

Errror 

-[NSConcreteNotification setText:]: unrecognized selector sent to instance 0x165a4270 
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteNotification setText:]: unrecognized selector sent to instance 0x165a4270' 

답변

0

서명이 있어야 통지에 의해 호출 당신의 방법

- (void)mySubViewNotification:(NSNotification *)note 

(소문자 첫 글자주의 - 표준 - 클래스 이름은 대문자로 시작을, 소문자와 방법, 그에 따라 코드를 업데이트 그리고 매개 변수는 방법, 그리고

추가 할 수있는) 통지되는 :

UILabel *label = note.object; 
label.textColor = [UIColor whiteColor]; 

알림은 매개 변수로 전달되고 사용자는 동봉 된 정보 (이 경우 레이블)를 가져와야하기 때문에

+0

감사하지만 알림 추가 오류가 발생했습니다. [NSNotificationCenter defaultCenter] addObserver : 셀렉터 : @selector (MySubViewNotification :) name : @ "MySubViewNotification"object : nil]; – Alan10977

+0

귀하의 의견을 이해할 수 없습니다. – Wain

+0

알림을 만들 때 [[NSNotificationCenter defaultCenter] addObserver : 셀렉터 : @selector (MySubViewNotification :) 이름 : @ "MySubViewNotification"개체 : nil]; 난 캐치되지 않은 예외 'NSInvalidArgumentException'으로 인해 응용 프로그램을 종료했습니다 이유 - '[MasterViewController MySubViewNotification :] : 인식 할 수없는 선택기가 인스턴스 0x15d4bcf0로 전송 됨' – Alan10977