Как передать объект с помощью NSNotificationCenter

Я пытаюсь передать объект от делегата моего приложения получателю уведомлений в другом классе.

Я хочу передать целое число 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 другому классу.

123
задан Dan Beaulieu 1 October 2015 в 04:18
поделиться