gpt4 book ai didi

ios - 在 NSNotification 中传递的访问对象?

转载 作者:IT王子 更新时间:2023-10-29 07:58:44 26 4
gpt4 key购买 nike

我有一个正在发布 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]);
}

当然会记录一个空值。

最佳答案

它是[通知对象]

您还可以使用 notificationWithName:object:userInfo: 方法发送用户信息

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com