首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用NSNotificationCenter传递对象

如何使用NSNotificationCenter传递对象
EN

Stack Overflow用户
提问于 2011-10-26 06:27:55
回答 2查看 118.3K关注 0票数 135

我正在尝试将一个对象从我的应用程序委托传递到另一个类中的通知接收器。

我想要传递整数messageTotal。现在我有:

在接收器中:

- (void) receiveTestNotification:(NSNotification *) notification
{
    if ([[notification name] isEqualToString:@"TestNotification"])
        NSLog (@"Successfully received the test notification!");
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissSheet) name:UIApplicationWillResignActiveNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveTestNotification:) name:@"eRXReceived" object:nil];

在执行通知的类中:

[UIApplication sharedApplication].applicationIconBadgeNumber = messageTotal;
[[NSNotificationCenter defaultCenter] postNotificationName:@"eRXReceived" object:self];

但是我想将对象messageTotal传递给另一个类。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7896646

复制
相关文章

相似问题

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