iOS开发 NSNotificationCenter 通知的使用方法

来源:互联网 发布:大数据销售 编辑:程序博客网 时间:2024/04/30 17:52
//发送通知到 (在需要的地方发送通知, 信息储存在userInfo(字典类型))
    [[NSNotificationCenterdefaultCenter] postNotificationName:NSNOTIFICATION_TAGobject:self userInfo:userInfo];

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

注:"NSNOTIFICATION_TAG" 我们自定义的标识符
0 0
原创粉丝点击