字典中的字典(作为 plist)
我有一个设置如下的 plist:
正如你所看到的,我在字典中有一本字典:每个父节点都有子节点,子节点本身就是一个字典,其中包含与其关联的图像和徽章。
我陷入困境的部分是如何将其转换为 NSOutlineView 的数据源。
目前我有这个:
NSString *paths = [[NSBundle mainBundle] pathForResource:@"navigationItems" ofType:@"plist"];
navigationItems = [[NSMutableDictionary alloc] initWithContentsOfFile:paths];
NSArray *parents = [navigationItems allKeys];
for (NSString *parent in parents) {
SourceListItem *parentItem = [SourceListItem itemWithTitle:parent identifier:parent];
NSArray *children = [parent allKeys];
NSLog(@"%@", children);
}
我打算对子级进行 for 循环,但问题是父级是 NSString 并且你不能 for 循环 NSString ..
那我该怎么办?
非常感谢
I have a plist that is set up like:
As you can see, I have a dictionary within a dictionary: each parent node has children nodes, which themselves are a dictionaryy with images and badges associated with them.
The part I'm stuck at is how to turn this into a datasource for a NSOutlineView..
At the moment I have this:
NSString *paths = [[NSBundle mainBundle] pathForResource:@"navigationItems" ofType:@"plist"];
navigationItems = [[NSMutableDictionary alloc] initWithContentsOfFile:paths];
NSArray *parents = [navigationItems allKeys];
for (NSString *parent in parents) {
SourceListItem *parentItem = [SourceListItem itemWithTitle:parent identifier:parent];
NSArray *children = [parent allKeys];
NSLog(@"%@", children);
}
I was going to then do a for loop with children, but the problem is is that parent is a NSString and you can't for loop over a NSString..
So what should I do?
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确地阅读了您的代码,则
parent
是您的 plist 中包含子字典的字典的键。在访问嵌入的子字典数据之前,您需要获取parent
在navigationItems
中引用的字典。例如:当您循环访问每个子项的键时,请记住以相同的方式访问每个子项的字典数据。
If I'm reading your code correctly,
parent
is a key for a dictionary containing child dictionaries in your plist. You need to grab the dictionary thatparent
refers to innavigationItems
before accessing the embedded child dictionary data. For example:Remember to access the dictionary data for each of the children in the same manner when you loop through their keys.