0

我初始化这个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'

看来我没有正确更改值。是语法错误吗?它是如何完成的?

4

2 回答 2

2

也许您拼错了方法的名称。

// WRONG
[[itensArray objectAtIndex:i] setString:APROVED forKey:STATE];

// GOOD
[[itensArray objectAtIndex:i] setValue:APROVED forKey:STATE];
于 2012-08-17T16:05:27.467 回答
1

'NSInvalidArgumentException',原因:'-[__NSCFDictionary setString:forKey:]:无法识别的选择器发送到实例 0x7b7d170'

NSMutableDictionary 没有 setString:forKey: 方法。

尝试 setObject:forKey:

[[itensArray objectAtIndex:i] setObject:APROVED forKey:STATE]; 
于 2012-08-17T16:03:20.763 回答