Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在模拟器的设置中更改区域格式,但应用程序中的区域设置不';不变_Ios_Xcode_Internationalization_Simulator - Fatal编程技术网

Ios 在模拟器的设置中更改区域格式,但应用程序中的区域设置不';不变

Ios 在模拟器的设置中更改区域格式,但应用程序中的区域设置不';不变,ios,xcode,internationalization,simulator,Ios,Xcode,Internationalization,Simulator,我使用NSDateFormatter的一个实例来帮助在我的应用程序中显示一个日期字符串,但在我将simulator中设置的区域格式从“美国”更改为“英国”后,设置中的示例显示日期为“2014年1月5日”,这证明更改成功。但当我在模拟器中打开我的应用程序时,日期仍然是“2014年1月5日”。 我使用以下代码检查我的应用程序中的区域设置: NSLocale *locale = [NSLocale currentLocale]; NSString *currentLocale = [locale ob

我使用NSDateFormatter的一个实例来帮助在我的应用程序中显示一个日期字符串,但在我将simulator中设置的区域格式从“美国”更改为“英国”后,设置中的示例显示日期为“2014年1月5日”,这证明更改成功。但当我在模拟器中打开我的应用程序时,日期仍然是“2014年1月5日”。 我使用以下代码检查我的应用程序中的区域设置:

NSLocale *locale = [NSLocale currentLocale];
NSString *currentLocale = [locale objectForKey:NSLocaleIdentifier];
NSLog(@"Current locale is %@", currentLocale);
它记录:当前的语言环境是en_US。 在模拟器设置中,我的应用程序似乎没有获得当前的语言环境。应该是我在模拟器设置中更改了区域设置,我的应用程序可以反映出更改。有什么问题吗? 日期格式代码为

static NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = NSDateFormatterMediumStyle;
dateFormatter.timeStyle = NSDateFormatterNoStyle;
self.dateLabel.text = [dateFormatter stringFromDate:item.dateCreated];
我使用的是iOS模拟器版本8.1、Xcode版本6.1.1、iOS 8.1、SDK 8.1


dateFormatter代码放在一个视图控制器的ViewWillExample方法中,在区域格式更改后,创建一个新的视图控制器仍然显示旧的区域设置。同样的结果甚至会杀死这个应用程序。我在表视图中注册并刷新区域设置更改通知。它可以反映语言环境的变化。无法理解差异。

您必须设置
NSDateFormatter

NSLocale *locale = [NSLocale currentLocale];
NSString *currentLocale = [locale objectForKey:NSLocaleIdentifier];
NSLog(@"Current locale is %@", currentLocale);


static NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setLocale:locale]; // <- Here

dateFormatter.dateStyle = NSDateFormatterMediumStyle;
dateFormatter.timeStyle = NSDateFormatterNoStyle;
self.dateLabel.text = [dateFormatter stringFromDate:item.dateCreated];
NSLocale*locale=[NSLocale currentLocale];
NSString*currentLocale=[locale objectForKey:NSLocaleIdentifier];
NSLog(@“当前语言环境为%@”,currentLocale);
静态NSDateFormatter*dateFormatter=[[NSDateFormatter alloc]init];

[dateFormatter setLocale:locale];// 我也有同样的问题。它看起来像是模拟器中的一个bug:

在setLocale之前,我在设置中更改为“英国”后,当前的Locale仍然是“en_US”。So[dateFormatter setLocale:locale];没有帮助。这是因为模拟器正在使用Mac的区域设置,即使您从模拟器设置更改了区域设置。如果您在实际设备上测试此功能,则需要该线路。感谢设备建议,尽管我尚未在设备上尝试我的应用程序。我要它现在在模拟器上工作。dateFormatter代码放在一个视图控制器的ViewWillExample方法中,在区域格式更改后,创建一个新的视图控制器仍然显示旧的区域格式。同样的结果甚至会杀死这个应用程序。我在表视图中注册区域设置更改通知并刷新。它可以反映语言环境的变化。我不明白其中的区别。有什么想法吗?