2011-08-15 1 views
0

내가 사용 알림 보내고있다 : 일부는 통지를 reaason를 들어NSNotification은 어디에서나 사용할 수 있습니까?

- (void) manageHistory: (NSNotification *) historyData{ 
    NSLog(@"this bit of code was run"); 
} 

: 사용

[[NSNotificationCenter defaultCenter] postNotificationName:@"historyLoaded" object:jsonReturn]; 

을 그리고 알림을 수신 :

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(manageHistory:) name:@"historyLoaded" object:nil]; 

그런 다음 선택의 방법입니다 통과하지 못한다. 앱의 어디서나 알림을 보내고받을 수 있습니까?

답변

1

postNotificationobject 매개 변수는 알림을 보내는 "개체"로 채워야하며, 보낸 사람이 반드시 지정되지 않으면 nil로 채워야합니다.
일부 정보를 전달하려면 postNotificationName:object:userInfo을 사용하고 대신 userInfo 사전에 정보를 입력해야합니다.

0
[[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(manageHistory) name:@"historyLoaded" object:nil]; 

[[NSNotificationCenter defaultCenter] postNotificationName:@"historyLoaded" 
     object:nil userInfo:jsonReturn]; 

- (void) manageHistory: (NSNotification *) historyData{ 
     NSDictionary* _dict = historyData.userInfo; 
     NSLog(@"Your information embedded to dictiuonary obj %@",_dict); 
} 

참고 : historyData이 postNotificationName

+0

내가 당신을 위해 일한다 위에 작성한 코드에 사전 객체해야합니다 있는지 확인합니다. –