Objective c 如何从NSMutableDictionary获取对象值?

Objective c 如何从NSMutableDictionary获取对象值?,objective-c,ios7,nsdictionary,Objective C,Ios7,Nsdictionary,我有一段代码,将对象放入NSMutableDictionary: SingletonDictionary *sd = [SingletonDictionary sharedDictionary]; UITextField *tf = (UITextField *)sender; int tagValue = tf.tag; // get the tag value [sd.dictionaryOfUserIndexes setObject:tf.text forKey:[NSStri

我有一段代码,将对象放入NSMutableDictionary:

SingletonDictionary *sd = [SingletonDictionary sharedDictionary];

UITextField *tf = (UITextField *)sender;  
int tagValue = tf.tag;  //  get the tag value

[sd.dictionaryOfUserIndexes setObject:tf.text forKey:[NSString stringWithFormat:@"%d", tagValue]];  //  value found in textField id'd by tag
SingletonDictionary *sd = [SingletonDictionary sharedDictionary];  //  initialize
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];  //  here too...
sd.dictionaryOfUserIndexes = [defaults objectForKey:@"importFileIDs"];  //  move from standardUserDefaults to dictionary singleton

NSLog(@"\n\nsd.dictionaryOfUserIndexes: %@", sd.dictionaryOfUserIndexes);


[sd.dictionaryOfUserIndexes[intTagValue]]];  //  move contents of textField from dictionary
textField.text = [sd.dictionaryOfUserIndexes objectForKey: tagValue];
更新:这是我试图检索字典内容的代码:

SingletonDictionary *sd = [SingletonDictionary sharedDictionary];

UITextField *tf = (UITextField *)sender;  
int tagValue = tf.tag;  //  get the tag value

[sd.dictionaryOfUserIndexes setObject:tf.text forKey:[NSString stringWithFormat:@"%d", tagValue]];  //  value found in textField id'd by tag
SingletonDictionary *sd = [SingletonDictionary sharedDictionary];  //  initialize
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];  //  here too...
sd.dictionaryOfUserIndexes = [defaults objectForKey:@"importFileIDs"];  //  move from standardUserDefaults to dictionary singleton

NSLog(@"\n\nsd.dictionaryOfUserIndexes: %@", sd.dictionaryOfUserIndexes);


[sd.dictionaryOfUserIndexes[intTagValue]]];  //  move contents of textField from dictionary
textField.text = [sd.dictionaryOfUserIndexes objectForKey: tagValue];
这是sd.DictionaryFuserIndex的内容:

}

第一列是UITextField的标记;第二列是该文本字段中的数据

词典的内容是有效的;我消除了构建错误,但是当我运行这个时,文本字段中没有任何内容

我看了又看,只希望我没有做傻事。有人能告诉我怎么了吗?

我知道了

textField.text = [sd.dictionaryOfUserIndexes objectForKey: [tagValue stringValue]];

谢谢大家抽出时间;非常感谢。

您正在向textField.text发送一条消息objectAtIndex:objectForKey:to textField.text。这似乎不对,[sd.DictionaryFuserIndex[intTagValue]]是什么意思?您的语法错误与您的标题或您尝试执行的任务完全无关。你在那条线上找不到大括号了。objectAtIndex:objectForKey:不是方法。在调用objectAtIndex:时需要大括号,然后必须处理gnasher已经指出的问题……而且,正如hotlicks刚刚指出的,在该表达式周围有太多大括号。把这条线分成单独的、单独有效的几行,看看发生了什么。是的,避免长链聚合物陈述,特别是当你试图理解一些东西的时候。使用几个临时变量将一个值从一行传递到下一行实际上不需要任何成本,但会使代码更易于理解和调试。