更新:无法将 NSDictionary 传递给 UITableViewCell textlabel
更新此线程,因为我有一些其他帮助解决了为什么我无法访问方法外部的 NSDictionarys 值...
我初始化错误,因此在方法末尾调用了 autorelease,所以当我在外部调用它时使用该方法时,我遇到了各种错误。
所以现在基本上我正在尝试将 NSDictionarys 值分配给 cellForRowAtIndexPath 内的 UITableViewCell Text,但是我收到此错误,
这是我尝试分配它的方式,此时的输出
// Configure the cell...
if(indexPath.row <= [self.sectionLetters count]){
// NSObject *key = [self.sectionLetters objectAtIndex:indexPath.row];
NSString *value = [self.arraysByLetter objectForKey:[self.sectionLetters objectAtIndex:indexPath.row]];
NSLog(@"thingy %@", value);
cell.textLabel.text = value;
}
return cell;
.output
2011-09-23 10:25:01.343 Code[6796:207] thingy (
Honda,
Honda,
Honda,
Honda,
Honda,
Honda,
Honda
)
但是,如果我注释掉 //Cell.textLabel.text = value;
我会得到此输出
.output2
2011-09-23 10:26:38.322 Code[6876:207] thingy (
Honda,
Honda,
Honda,
Honda,
Honda,
Honda,
Honda
)
2011-09-23 10:26:38.323 Code[6876:207] thingy (
Mazda,
Mazda,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Mitsubishi
)
2011-09-23 10:26:38.325 Code[6876:207] thingy (
Nissan,
Nissan,
Nissan,
Nissan,
Nissan,
Nissan,
Nissan
)
2011-09-23 10:26:38.326 Code[6876:207] thingy (
Toyota,
Toyota,
Toyota
)
Updating this Thread as I have had some other help solving why I was not able to access the NSDictionarys values outside the method...
I was initalizing it wrong thus autorelease was being called at the end of the method so when I was calling it outside of that method I was getting all sorts of errors..
So now basically I am trying to allocate the NSDictionarys values to the UITableViewCell Text inside cellForRowAtIndexPath however I am getting this error
here is how I am trying to allocate it and the output at this point
// Configure the cell...
if(indexPath.row <= [self.sectionLetters count]){
// NSObject *key = [self.sectionLetters objectAtIndex:indexPath.row];
NSString *value = [self.arraysByLetter objectForKey:[self.sectionLetters objectAtIndex:indexPath.row]];
NSLog(@"thingy %@", value);
cell.textLabel.text = value;
}
return cell;
.output
2011-09-23 10:25:01.343 Code[6796:207] thingy (
Honda,
Honda,
Honda,
Honda,
Honda,
Honda,
Honda
)
however, if I comment out //Cell.textLabel.text = value;
I get this output
.output2
2011-09-23 10:26:38.322 Code[6876:207] thingy (
Honda,
Honda,
Honda,
Honda,
Honda,
Honda,
Honda
)
2011-09-23 10:26:38.323 Code[6876:207] thingy (
Mazda,
Mazda,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Mitsubishi
)
2011-09-23 10:26:38.325 Code[6876:207] thingy (
Nissan,
Nissan,
Nissan,
Nissan,
Nissan,
Nissan,
Nissan
)
2011-09-23 10:26:38.326 Code[6876:207] thingy (
Toyota,
Toyota,
Toyota
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你知道吗,我想我知道问题所在,所以我要做一个猜测。
因为您直接使用 arraysByLetter,所以我不相信您会遇到合成属性,而是会遇到支持变量。您需要使用 self.arraysByLetter (这将保留字典)。
至少,我一直在使用 self.property,所以我不记得这是必需品还是只是一种习惯。试一试。
You know what, I think I know the problem so I'm going to make a guess.
Because you're using arraysByLetter directly, I don't believe you're hitting the synthesized properties, but the backing variable instead. You need to use self.arraysByLetter (this will retain the Dictionary).
At least, I've been using self.property forever, so I can't remember if this was a necessity or just a habit. Give that a shot.