我初始化了这个NSMutableDictionary
:
define TAREFA @"TAREFA"
define DATA_ITEM @"DATA"
define HORA_ITEM @"HORAS"
define ID @"ID"
define STATE @"NA"
define APROVED @"APROVED"
define REJECTED @"REJECTED"
itensArray = [[NSMutableArray alloc] init];
for (int i=0; i< [listagens size]; i++)
{
NSMutableDictionary *tmpDictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
[[listagens item:i] WI_ID], ID,
[[listagens item:i] WI_TEXT], TAREFA,
[[listagens item:i] WI_CD], DATA_ITEM,
[[listagens item:i] WI_CT], HORA_ITEM,
STATE, STATE,
nil];
[itensArray addObject:tmpDictionary];
}
稍后,我会执行以下操作:
for (int i=0; i<[itensArray count]; i++)
{
if ([[[itensArray objectAtIndex:i] objectForKey:ID] isEqualToString:cell.idLabel.text]) {
[[itensArray objectAtIndex:i] setString:APROVED forKey:STATE];
break;
}
}
我初始化数组,然后稍后,我更改了NSMutableDictionary的字符串。当我设置值时,我得到以下运行时错误:
'NSInvalidArgumentException',原因:' - [__ NSCFDictionary setString:forKey:]:无法识别的选择器发送到实例0x7b7d170'
看来我没有正确改变价值。这是语法错误吗?怎么做?
答案 0 :(得分:2)
也许你拼错了方法的名称。
// WRONG
[[itensArray objectAtIndex:i] setString:APROVED forKey:STATE];
// GOOD
[[itensArray objectAtIndex:i] setValue:APROVED forKey:STATE];
答案 1 :(得分:1)
'NSInvalidArgumentException',原因:' - [__ NSCFDictionary setString:forKey:]:无法识别的选择器发送到实例0x7b7d170'
NSMutableDictionary没有setString:forKey:方法。
尝试setObject:forKey:
[[itensArray objectAtIndex:i] setObject:APROVED forKey:STATE];