gpt4 book ai didi

iphone - 在uidatepicker上设置日期错误

转载 作者:行者123 更新时间:2023-12-03 21:23:40 24 4
gpt4 key购买 nike

我被下面的代码难住了。我将一个字符串日期传递给 UIDatePicker,它似乎适用于大多数设备,但在某些设备上,它会使应用程序崩溃。

这是代码

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH:mm"];
NSDate *date = [dateFormat dateFromString:dateStr];
[timePicker setDate:date];
[dateFormat release];

我有一个传递“dateStr”变量的函数,如下所示,dateStr = @"0:0";我看不出出了什么问题 - 因为它对我有用! (iphone 3.1.3) 但它不适用于我的测试仪 (ipod touch 3.1.3)

有人能看出代码有什么问题吗?

非常感谢。有什么想法吗?

最佳答案

可能是语言环境问题。

尝试为日期格式化程序设置通用区域设置,例如

NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormat setLocale:usLocale];
[usLocale release];

关于iphone - 在uidatepicker上设置日期错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2573980/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com