ITeye博客

NotifiCationCenter控制使用

zcw_java · 2013-07-02 11:31 · iPhone开发 · 移动开发 · Markdown

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];
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。