NotifiCationCenter控制使用

[align=center]NSNotificationCenter[/align]

第一种,这个只是传值,通过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];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值