NSDictionaryController doesn't seem to observe changes to content dictionary

烂漫一生 提交于 2019-12-06 10:41:49

问题


I must be missing something simple, but I am having some trouble binding a tableView to an NSDictionaryController. Here is a model of my current scheme:

TableViewColumn --bindsTo-->DictionaryController.arrangedObjects.(value or key) --bindsTo-->someClass.someClassMember.aDictionary.

I've tested the tableView by adding an entry to aDictionary on init, which is displayed correctly. But when another method produces an object that is then added to aDictionary, the TableView doesn't seem to update or even know that aDictionary now has two entries. I've tried everything I can think of. I am not directly accessing aDictionary....I've tried (in someClassMember) [self aDictionary setValue:forKey:], and [self setValue:forKeyPath:@"aDictionary"] and similar variations. The key is a string, so it should be KVC/KVO compliant, and I have '@synthesize'd aDictionary in someClassMember.

What am I missing? Why won't new entries to the dictionary show up in the tableView?

Thanks in advance


回答1:


Try [self willChangeValueForKey:@"aDictionary"]; before adding the new item, and [self didChangeValueForKey:@"aDictionary"]; afterwards in someClass



来源:https://stackoverflow.com/questions/1596229/nsdictionarycontroller-doesnt-seem-to-observe-changes-to-content-dictionary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!