我正在尝试使用 NSNotificationCenter 将 NSDictionary 从 UIView 传递给 UIViewController。发布通知时字典工作正常,但在接收方法中我无法访问字典中的任何对象。
这是我创建字典和发布通知的方式...
itemDetails = [[NSDictionary alloc] initWithObjectsAndKeys:@"Topic 1", @"HelpTopic", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"HotSpotTouched" object:itemDetails];
在 UIViewController 我正在设置观察者......
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hotSpotMore:)
name:@"HotSpotTouched"
object:nil];
出于测试目的,hotSpotMore 看起来像这样......
- (void)hotSpotMore:(NSDictionary *)itemDetails{
NSLog(@"%@", itemDetails);
NSLog(@"%@", [itemDetails objectForKey:@"HelpTopic"]);
}
第一个 NSLog 可以很好地显示字典的内容。第二个日志引发以下异常...
[NSConcreteNotification objectForKey:]: unrecognized selector sent to instance 0x712b130
我不明白为什么我无法访问传递的字典中的任何对象。
提前感谢您的帮助。
约翰