Xcode Simulation在UITableView Subtitle中显示值,但是IPad显示<null> </null>

时间:2014-01-10 21:34:42

标签: xcode ipad uitableview ios-simulator subtitle

在我的项目中,我创建了一个包含各种不同变量的String,然后将其插入到我的字幕中。模拟器显示它的位置。然而在IPad上,它只显示一个变量而不是任何其他变量的NULL。有没有人遇到过类似的问题?

由于我无法发布图片(到目前为止没有足够的声誉),我只需要通过输入来重建它:

IOS模拟器:

............................................... .................

Thomas Winter

2014-01-05 - Dauer:0,5 h

............................................... .................

真实设备:

............................................... .................

Thomas Winter

2014-01-05 - Dauer:(null)h

............................................... .................

使用initStringWithFormat方法将String放在一起,其中包含变量。看到h在副标题中是如何存在的,但在它之前的持续时间没有,我只能认为变量在实际设备上已经不存在了

NSNumberFormatter * formatter = [[NSNumberFormatter alloc] init];

[formatter setNumberStyle:NSNumberFormatterDecimalStyle];

[formatter setMaximumFractionDigits:2];

NSString * dauerString =[[NSString alloc]initWithFormat:@"Dauer: %@h",[formatter numberFromString:[[self.leistungListe objectAtIndex:indexPath.row]getDauer]]];

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];

[dateFormat setDateFormat:@"YYYY-MM-dd"];

NSString * dateString = [dateFormat stringFromDate:[[self.leistungListe objectAtIndex:indexPath.row]getDatum]];

NSString * detailTextString = [[NSString alloc]initWithFormat:@"%@ - %@",dateString,dauerString];

cell.detailTextLabel.text =detailTextString;

1 个答案:

答案 0 :(得分:0)

可能是您的模拟器和设备上的区域设置不同。如果要转换为数字的字符串是固定格式,则需要指定此精确格式,包括使用的小数和千位分隔符。

将数字格式化程序设置为“十进制样式”会从设备或模拟器中获取各种设置,特别是用于分隔小数的字符 - 在欧洲大部分地区它是逗号(例如Pi是3,14159 ....)但在其他地方它是一个时期(3.14159)。您要转换的字符串将具有其中一个,它将匹配模拟器区域设置中使用的小数分隔符,并且设备的区域设置将具有另一个。当数字格式化程序读取它无法转换的字符串时,它返回nil,这就是您所看到的。

手动设置格式,或考虑使用不同的方法 - 除了从文本文件,Web服务或用户条目初始解析之外,没有理由将数字保存为字符串。