`
zcw_java
  • 浏览: 296956 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

NotifiCationCenter控制使用

 
阅读更多
NSNotificationCenter


第一种,这个只是传值,通过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];
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics