2016-11-15 72 views
0

我想在整個項目中將日曆設置爲默認格里曆。 即使用戶在設備設置中更改日曆。但我希望日曆只顯示格利高裏。在我的情況下,我不想使用此代碼。如何在整個項目中設置默認日曆爲陽曆?目標c

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

我想將日曆默認設置爲格利高利而不使用它。還有什麼可以做的嗎?就像在Info.plist中設置日曆一樣。請建議我。非常感謝你。

+0

使用帶有'static'的全局變量或創建si ngleton課程舉行它 – Tj3n

+0

你能告訴我示例代碼嗎?感謝您的耐心。 –

回答

1

創建一個Singleton類或創建像這樣的appDelegate級的全球varibale:

添加在你的AppDelegate的頭文件:

@property (nonatomic,strong) NSCalendar *gregorian; 

添加在你的AppDelegate的Implmenation文件:

使用像這樣:

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; 
} 
相關問題