4th*_*ace 55 iphone xcode cocoa-touch objective-c
要按顺序显示NSMutableDictionary中的键/值(在tableview中),我需要通过索引访问它们.如果通过索引访问可以在该索引处给出密钥,那么我可以获得该值.有没有办法做到这一点或不同的技术?
Ben*_*nno 122
您可以使用allKeys方法获取包含对象键的NSArray.然后,您可以按索引查看.请注意,键出现在数组中的顺序是未知的.例:
NSMutableDictionary *dict;
/* Create the dictionary. */
NSArray *keys = [dict allKeys];
id aKey = [keys objectAtIndex:0];
id anObject = [dict objectForKey:aKey];
Run Code Online (Sandbox Code Playgroud)
编辑:实际上,如果我理解你想要做什么你想要的东西很容易使用快速枚举,例如:
NSMutableDictionary *dict;
/* Put stuff in dictionary. */
for (id key in dict) {
id anObject = [dict objectForKey:key];
/* Do something with anObject. */
}
Run Code Online (Sandbox Code Playgroud)
编辑:修正马可指出的拼写错误.
| 归档时间: |
|
| 查看次数: |
74923 次 |
| 最近记录: |