首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在NSNotification中传递userInfo?

如何在NSNotification中传递userInfo?
EN

Stack Overflow用户
提问于 2010-10-05 15:07:22
回答 4查看 53.7K关注 0票数 49

我正在尝试使用NSNotification发送一些数据,但是遇到了问题。下面是我的代码:

代码语言:javascript
复制
// Posting Notification
NSDictionary *orientationData;
if(iFromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
    orientationData = [NSDictionary dictionaryWithObject:@"Right"
                                                  forKey:@"Orientation"];
}

NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter postNotificationName:@"Abhinav"
                                  object:nil
                                userInfo:orientationData];

// Adding observer
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(orientationChanged)
                                             name:@"Abhinav"
                                           object:nil];

现在如何在我的选择器orientationChanged中获取这个userInfo字典

EN

Stack Overflow用户

发布于 2010-10-05 15:21:55

您的选择器必须具有:才能接受参数。

例如:

代码语言:javascript
复制
@selector(orientationChanged:)

然后在方法声明中,它可以接受NSNotification参数。

票数 23
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3861493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档