我有一个NSArray所以当我这样做时:
NSLog(@"%@", [jokesArray description]);
我得到以下内容:
(
{
"_id" = {
"$id" = 4e91fd49c7e24cda74000000;
};
author = draper;
comments = (
{
author = adias;
comment = "amazing again";
}
);
created = {
sec = 1318118400;
usec = 0;
};
text = "This is a random post again";
title = "post # 2";
type = (
punjabi
);
},
{
"_id" = {
"$id" = 4e8cf1d6c7e24c063e000000;
};
author = faisal;
comments = (
{
author = adias;
comment = amazing;
},
{
author = nike;
comment = "I concur";
}
);
created = {
sec = 1317772800;
usec = 0;
};
text = "This is a random post";
title = "post # 1";
type = (
punjabi
);
}
)
如何访问特定元素中的文本键?
我尝试时收到错误:
[[cell textLabel]setText:[[jokesArray objectAtIndex:[indexPath row]]valueForKey:@"text"]];
答案 0 :(得分:1)
EXC_BAD_ACCESS表示您正在提供错误的指针。也许你未能妥善保留jokesArray?
答案 1 :(得分:1)
暂停NSLog语句。运行您的应用程序,然后使用调试器不断向jokesarray添加图层。例如,当您点击断点时,进入调试器,然后键入
po jokesArray
如果显示正确,请输入:
po [jokesArray objectAtIndex:[indexPath row]]
如果有效,请输入您的全部内容:
po [[jokesArray objectAtIndex:[indexPath row]]valueForKey:@"text"]]
如果可以,那么你的问题不在于访问jokesArray。