【发布时间】:2011-12-15 08:21:42
【问题描述】:
我正在尝试将一个对象从我的应用委托传递给另一个类中的通知接收器。
我想传递整数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 传递给其他类。
【问题讨论】:
-
对于 swift 2.0 和 swift 3.0 stackoverflow.com/questions/36910965/…
标签: objective-c swift cocoa-touch nsnotificationcenter nsnotifications