如何在整个项目中将默认日历设置为公历?目标c [英] How can I set default calendar to gregorian in the Whole project? Objective c

查看:63
本文介绍了如何在整个项目中将默认日历设置为公历?目标c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在整个项目中将日历设置为默认的公历.甚至用户也可以在设备设置"中更改日历.但我希望日历只显示公历.就我而言,我不想使用此代码.

I want to set the calendar to default Gregorian in whole project. Even user change the calendar in Device Settings. But I want the calendar to only show the gregorian. In my case I don't want to use this code.

NSCalendar *gregcalendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
[formatter setCalendar:gregcalendar];

我想不使用日历将日历默认设置为公历.还有什么要做的吗?就像在Info.plist中设置日历一样.请给我建议.非常感谢.

I want to set the calendar default to gregorian without using it. Is there anything else to do it? Like as set the calendar in Info.plist or something else. Please suggest me. Thank you very much.

推荐答案

创建单例类或在appDelegate类中创建全局变量,如下所示:

Create a Singleton class Or Create global varibale in appDelegate class like this:

添加AppDelegate的头文件:

Add In Header File of your AppDelegate:

@property (nonatomic,strong) NSCalendar *gregorian;

添加AppDelegate的示例文件:

Add In Implmenation file of your AppDelegate:

像这样使用:

self.gregorian = [self calendar];

- (NSCalendar*)calendar
{
    if (self.gregorian == nil) {
        NSCalendar* temc = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

        NSLocale* usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"Add local code";

        self.gregorian = temc;
    }
    return gregorian;
}

这篇关于如何在整个项目中将默认日历设置为公历?目标c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆