iPhone应用程序崩溃[__NSCFString objectForKey:]无法识别的选择器发送到实例 [英] iPhone app crash [__NSCFString objectForKey:] unrecognized selector sent to instance
问题描述
我试图在tempArray中添加偶数个data.localBookmarks是字典数组。这是我的代码:
I am trying to add in tempArray only even number of data.localBookmarks is array of dictionary. Here is my code :
currentIndex = indexPath.row;
for (NSDictionary *dict in localBookmarks)
{
if (currentIndex % 2 == 0 && currentIndex <= [localBookmarks count])
{
[tempArray addObject:[dict objectForKey:@"firstName"]];
}
currentIndex++;
}
NSLog(@"tempArray %@",tempArray);
cell.textLabel.text = [tempArray objectAtIndex:indexPath.row];
return cell;
我的应用程序崩溃[tempArray addObject:[dict objectForKey:@firstName]];这一行,我该如何解决?
my app crash on [tempArray addObject:[dict objectForKey:@"firstName"]]; this line ,How can I fix it?
推荐答案
为什么会崩溃
您认为是NSDictionary的变量 dict
实际上是一个NSString。由于字符串不响应 objectForKey:
方法,因此您的应用程序崩溃了。这就是错误消息告诉你的。
Why you are crashing
The variable dict
that you think is a NSDictionary is actually a NSString. Since strings don't respond to the objectForKey:
method your app crashed. That is what the error message is telling you.
你的陈述:数据。 localBookmarks是字典数组是假的。其中至少有一个只是一个字符串。
Your statement: "data.localBookmarks is array of dictionary" is false. At least one of them is just a string.
检查 localBookmarks
的来源。如果您正在解析它的数据,则可能需要更改它。
Check where your localBookmarks
comes from. If it's data you are parsing you may need to change that.
这篇关于iPhone应用程序崩溃[__NSCFString objectForKey:]无法识别的选择器发送到实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!