从 NSDictionary 内部显示 NSArray 列表?
我正在开发一个供个人使用的应用程序,该应用程序会随机显示相关单词的列表。
在这个社区的帮助下,我将相关单词列表放入 NSArrays 中。例如:
NSArray *catList = [NSArray arrayWithObjects:@"Lion", @"Snow Leopard", @"Cheetah", nil];
NSArray *dogList = [NSArray arrayWithObjects:@"Dachshund", @"Pitt Bull", @"Pug", nil];
...
我已将这些数组放入 NSDictionary 中:
NSMutableDictionary *wordDictionary = [[NSMutableDictionary alloc] init];
[wordDictionary setObject: catList forKey:@"Cats"];
[wordDictionary setObject: dogList forKey:@"Dogs"];
...
我想做的是随机选择 NSDictionary 键之一并显示其数组中保存的 NSString 列表。显然 [wordDictionary objectForKey: @"Cats"];
允许我访问设置为 Cats 键的 catList 数组,以显示数组中保存的字符串列表。但我想随机显示列表而不指定密钥。
我尝试了 [wordDictionary allKeys]
并且可以随机显示键的名称,但不能显示数组中保存的列表。
有没有人有任何从 NSDictionary 显示 NSArray 列表的指针?
非常感谢。
I'm working on an app for personal use that displays lists of associated words randomly.
With help from this community I've put lists of associated words into NSArrays. For example:
NSArray *catList = [NSArray arrayWithObjects:@"Lion", @"Snow Leopard", @"Cheetah", nil];
NSArray *dogList = [NSArray arrayWithObjects:@"Dachshund", @"Pitt Bull", @"Pug", nil];
...
And I've put those arrays into an NSDictionary:
NSMutableDictionary *wordDictionary = [[NSMutableDictionary alloc] init];
[wordDictionary setObject: catList forKey:@"Cats"];
[wordDictionary setObject: dogList forKey:@"Dogs"];
...
What I'd like to do is randomly select one of the NSDictionary keys and display the list of NSStrings held in its array. Obviously [wordDictionary objectForKey: @"Cats"];
allows me to access the catList array set to the Cats key to display the string list held in the array. But I'd like to display the lists randomly and without specifying the key.
I experimented with [wordDictionary allKeys]
and could randomly display the name of a key but not the list held in the array.
Does anyone have any pointers for displaying an NSArray list from an NSDictionary?
Thanks very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是你想要的吗?
Is this what you want?