- [__ NSDictionaryI setObject:forKey:]:无法识别的选择器发送到实例0x91da0f0

时间:2013-06-12 04:52:58

标签: ios nsmutabledictionary

当我在nsmutabledictionary中设置值时,然后给出错误显示在下面的图像中....

enter image description here

这里是我在nsmutabledictionary

中的setvalue代码
NSMutableArray *countArray=[[NSMutableArray alloc] init];
for (int i=0;i<artistName.count;i++)
{
    int count=0;
    NSMutableDictionary *dir1=[artistName objectAtIndex:i];
    NSString *artist1=[dir1 objectForKey:@"SONG_ARTIST"];

    for (int j=0;j<CurrentPlayingSong.count;j++)
    {
        NSDictionary *dir2=[CurrentPlayingSong objectAtIndex:j];
        NSString *artist2=[dir2 objectForKey:@"SONG_ARTIST"];

        if ([artist2 isEqualToString:artist1])
        {
            count++;
        }
    }

    NSString *Size=[[NSString alloc] initWithFormat:@"%d",count];
    [dir1 setObject:Size forKey:@"SIZE"];

    [countArray addObject:dir1];
}
return countArray;

1 个答案:

答案 0 :(得分:10)

这个NSMutableDictionary *dir1=[artistName objectAtIndex:i];返回一个NSDictionary对象,它将你的dir1转换为相同的类型。

最好的方法是做这样的事情:

NSMutableDictionary *dir1=[NSMutableDictionary dictionaryWithDictionary:[artistName objectAtIndex:i]];

NSMutableDictionary *dir1 = [artistName[i] mutableCopy];

这将确保dir1始终为NSMutableDictionary。

希望这会有所帮助