加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 使用NSNotificationCenter向另一个班级发送通知

发布时间:2020-12-16 09:36:13 所属栏目:百科 来源:网络整理
导读:所以我的目标是使用NSNotificationCenter向另一个类发送通知,我也想将带有通知的对象传递给另一个类,我该怎么做? 解决方法 您必须先注册通知名称 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startLocating:) name:@"Force
所以我的目标是使用NSNotificationCenter向另一个类发送通知,我也想将带有通知的对象传递给另一个类,我该怎么做?

解决方法

您必须先注册通知名称

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startLocating:) name:@"ForceUpdateLocation" object:nil]; // don't forget the ":"

然后发布带有参数字典的通知

[[NSNotificationCenter defaultCenter] postNotificationName:@"ForceUpdateLocation" object:self userInfo:[NSDictionary dictionaryWithObject:@"1,2,3,4,5" forKey:@"categories_ids"]];

而且方法将是

- (void)startLocating:(NSNotification *)notification {

    NSDictionary *dict = [notification userInfo];
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读