objective-c 如何在Objective-C中获取字典中每个键的值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2286186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the value for each key in dictionary in Objective-C?
提问by suse
I'm maintaining a NSMutableDictionarywhich holds key and value pair.Now i need to perform some operation for each value in it.How to retrive value from dictionary.
我正在维护一个NSMutableDictionary包含键和值对的对象。现在我需要对其中的每个值执行一些操作。如何从字典中检索值。
// this is NSMutableDIctionary
NSMutableDictionary *dictobj = [[NSMutableDictionary alloc]init];
// in methodA
-(void)methodA
{
//get the value for each key and peform an operation on it.
}
How to proceed? plz help
如何进行?请帮忙
回答by dreamlax
for (id key in dictobj)
{
id value = [dictobj objectForKey:key];
[value doSomething];
}
回答by andyvn22
I'm not entirely clear what your question is asking, but you might be looking for:
我不完全清楚您的问题在问什么,但您可能正在寻找:
for (id currentValue in [dictobj allValues])
{
//stuff with currentValue
}
回答by Ravi Kumar
NSArray *array = [viewControllers allValues];
for (int i = 0; i<array.count; i++) {
MenuListingVC *vc = array[i];
[vc tableDataReload];
}

