我正在尝试检索 NSDictionary 中键的值。字典已使用字符串类型的键值对初始化。问题是,我似乎无法通过调用 objectForKey 或 valueForKey 来检索值。
我能够遍历字典并打印键和值。
有人能指出我哪里出错了吗?这是我的代码...
//Set up dictionary with options
keys = [NSArray arrayWithObjects:@"red", @"blue", nil];
values = [NSArray arrayWithObjects:@"1.7", @"2.8", nil];
conversionOptions = [NSDictionary dictionaryWithObject:values
forKey:keys];
然后在选择器中的选择行上调用它
NSLog(@"... %@", [keys objectAtIndex:row]); //prints out the key
NSString *theString = [keys objectAtIndex:row]; //save it as a string
NSLog(@"The string is... %@", theString); //print it out to make sure im not going crazy
NSLog(@"the value is : %@",[conversionOptions objectForKey:theString]); // I just get NULL here
//NSLog(@"the value is : %@",[conversionOptions valueForKey:theString]); // This doesn't work either, I just get NULL