您的位置:首页 > 移动开发 > IOS开发

iOS通知中心NSNotificationCenter

2015-12-01 15:47 405 查看
注:一个应用程序中只有一个通知中心

/// @brief 创建一个通知中心对象

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

/// @brief 向通知中心注册观察者,第一个参数为观察的对象所在类,第二个参数为观察到以后所调用的方法,第三个参数为观察的事件,第四个参数为要传的参数

[nc addObserver:self selector:@selector(keyboardShowUp) name:UIKeyboardWillShowNotification object:nil];

/// @brief 发送通知,第三个参数为发送的消息

[[NSNotificationCenter defaultCenter] postNotifiationName:@"发送的通知名" object:self userInfo:dict];

/// @brief 获取通知消息,noti为通知中心的对象名

NSDictionary *dict = noti.userInfo

/// @brief 从通知中心移除观察者

[[NSNotificationCenter defaultCenter] removeObserver:self];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: