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

iOS开发 NSNotificationCenter 通知的使用方法

2016-10-25 14:32 232 查看
//发送通知到 (在需要的地方发送通知, 信息储存在userInfo(字典类型))

    [[NSNotificationCenter
defaultCenter] postNotificationName:NSNOTIFICATION_TAG
object:self
userInfo:userInfo];

 //z在需要的地方接受通知
    [[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(messageNotifacation:)
name:NSNOTIFICATION_TAG
object:nil];
//方法
- (void)messageNotifacation:(NSNotification
*)notification {
   
NSDictionary *userInfo = notification.userInfo;
信息可以从userInfo中取出
}

注:"NSNOTIFICATION_TAG" 我们自定义的标识符
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息