奇数NSNumber输出 - 核心数据

时间:2011-10-11 00:19:17

标签: iphone objective-c xcode core-data

当关注CoreDataBooks示例代码并将其实现到我的应用程序中时,我遇到了一个非常奇怪的错误/故障与NSNumber(整数16)。

当我有代码时

cell.detailTextLabel.text = [NSString stringWithFormat:@"%i", child.marblesneeded];

detailTextLabel显示一个奇数字符串,每次我尝试更改数字时都会更改这些数字。请参见附图。目前,它应显示0但显示112917120。enter image description here

谢谢!

2 个答案:

答案 0 :(得分:2)

试试这个:

cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", [child.marblesneeded intValue]];

答案 1 :(得分:2)

NSNumber有一个方法可以将数字作为字符串返回,可以用作标签文本,如下所示:

cell.detailTextLabel.text = [child.marblesneeded stringValue];