我有一个发布了NSDictionary的NSNotification:

 NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
                                          anItemID, @"ItemID",
                                          [NSString stringWithFormat:@"%i",q], @"Quantity",
                                          [NSString stringWithFormat:@"%@",[NSDate date]], @"BackOrderDate",
                                          [NSString stringWithFormat:@"%@", [NSDate date]],@"ModifiedOn",
                                          nil];

                    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"InventoryUpdate" object:dict]];

我如何订阅此书并从此NSDictionary获得信息?

在我的viewDidLoad中,我有:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recieveInventoryUpdate:) name:@"InventoryUpdate" object:nil];

和该类中的方法:
- (void)recieveInventoryUpdate:(NSNotification *)notification {
    NSLog(@"%@ updated", [notification userInfo]);
}

当然,它会记录一个空值。

最佳答案

这是[notification object]
您也可以使用notificationWithName:object:userInfo:方法发送userinfo

关于ios - 访问对象在NSNotification中传递?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6748614/

10-10 04:16