【发布时间】:2012-06-13 22:41:11
【问题描述】:
我在获取已从浮点数转换为显示在 UITableView 的自定义单元格中的标签中的字符串时遇到问题。
如果我尝试将浮点值分配给标签,程序将会崩溃。如果我离开 "strAIAreaIncrease = @"6.5%";"未注释,程序运行良好 - 但没有计算值。
strAIAreaIncrease = [NSString stringWithFormat:@"%.2f",fltAreaIncrease];
strAIAreaIncrease = [strAIAreaIncrease stringByAppendingString:@"%"];
DebugLog(@"The value of float num is %.2f", fltAreaIncrease);
DebugLog(@"The value of the string is %@", strAIAreaIncrease);
// strAIAreaIncrease = @"6.5%";
调试器控制台显示如下:
2010-11-14 19:52:38.122 Building Use[855:207] float num 的值为 2.50 2010-11-14 19:52:38.123 Building Use[855:207] 字符串的值为 2.50%
我在其他自定义单元格标签上使用了这种格式,没有问题。有人知道发生了什么吗?
谢谢。
【问题讨论】:
-
几乎没有enough information。如何为标签分配浮点数?你是如何定制细胞的?您的代码是否适用于标准表格单元格?坠机原因是什么?堆栈跟踪是什么? (最后两个可以在crash logs、accessible via the Organizer找到)我们真正需要的是minimal test case。
-
"如何为标签分配浮点数?" - 这就是我的全部问题。我正在尝试将浮点数更改为字符串,以使其在标签中读出。这种方法已经在同一个程序中的其他单元格上工作了,但是如果来回足够多,程序就会崩溃。我认为这是由于我在不断更新字符串时读到的内存泄漏。我仍在了解崩溃日志,并将更深入地研究您的建议。谢谢。
标签: iphone string crash floating-point