[align=center]NSNotificationCenter[/align]
第一种,这个只是传值,通过NSNotification获取,当然也可以直接使用obj
注册A
响应B
第二种多值传输(obj)
注册A
响应B
数组传输,注意响应消息的userInfo一定是NSDictionary类型
第一种,这个只是传值,通过NSNotification获取,当然也可以直接使用obj
注册A
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enableOrDisableAudio:) name:@"enableOrDisableAudio" object:nil];
- (void)enableOrDisableAudio:(NSNotification *)notification
{
printf("enableOrDisableAudio\n");
BOOL bIsEnableAudio = [[notification object] boolValue];
self.m_bIsEnable = bIsEnableAudio;
[self enableAudio:bIsEnableAudio];
}
响应B
NSNumber *boolNum = [NSNumber numberWithBool:m_bIsSPKOn];
[[NSNotificationCenter defaultCenter] postNotificationName:@"enableOrDisableAudio" object:boolNum];
第二种多值传输(obj)
注册A
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object: nil];
- (void)reachabilityChanged:(NSNotification *)note
{
Reachability *curRech = [note object];
NetworkStatus status = [curRech currentReachabilityStatus];
if (status == NotReachable)
{
[self setStatusBarToShow];
[SVStatusHUD showWithMessage:Localized(@"disconnect from network") duration:KShortDuration];
}
else
{
[self resetStatusBarBlank];
}
}
响应B
Reachability* noteObject = (Reachability*) info;
// Post a notification to notify the client that the network reachability changed.
[[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject];
数组传输,注意响应消息的userInfo一定是NSDictionary类型
- (void) keyboardWillShow:(NSNotification *)aNotification
{
NSDictionary *userInfo = [aNotification userInfo];
}