gpt4 book ai didi

iphone - 努力让字典通过 NSNotification

转载 作者:行者123 更新时间:2023-11-28 22:52:37 25 4
gpt4 key购买 nike

收到通知所以处理

-(void) dateSelected:(NSNotification *) notification
{
NSLog(@"Value: %@", [[notification userInfo] valueForKey:@"date"] );
NSMutableDictionary * dateDict = [[NSDictionary alloc] initWithDictionary:[notification userInfo]];
NSLog(@"The Date Dict: %@", dateDict );
}

我得到的日志是

2012-07-20 11:32: TestApp[10701:40b] Value: (null)
2012-07-20 11:32: TestApp[10428:40b] The Date Dict: {
}

如果我 NSLog 出通知本身它看起来有效:

2012-07-20 11:33: TestApp[10457:40b] Notification: NSConcreteNotification 0x16629460 {name = date_selected_; object = {
date = 20120705;
}}

我以前做过这个并且很有效。

我确信它很简单,但今天我看不到问题。

如有任何帮助,我们将不胜感激。

谢谢,-代码

最佳答案

这很简单,看看您的日志输出...您的通知中没有设置userInfo。只有名称对象。将您的输出与此输出进行比较 ...

NSNotification *notification = [NSNotification notificationWithName:@"NAME"
object:self
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"obj", @"key", nil]];
NSLog( @"NOT: %@", notification );

...

NOT: NSConcreteNotification 0x73586f0 {name = NAME;
object = <CMAppDelegate: 0x884a4e0>; userInfo = {
key = obj;
}}

...看到区别了吗?日志输出中有nameobject,还有userInfo

所以答案是 - 您的通知不包含 userInfo 字典。查看触发此通知的代码。

关于iphone - 努力让字典通过 NSNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11577870/

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