2012-08-24 84 views
1

是沒有任何理由ECGraph會在模擬器上運行良好,但還沒有給我這個錯誤,當我在我的設備上運行它:ECGraph不工作的設備,但它只是對模擬器

2012-08-24 01:57:18.543 Portfolio[3538:907] *** -[__NSCFCalendar     components:fromDate:toDate:options:]: fromDate cannot be nil 
I mean really, what do you think that operation is supposed to mean with a nil fromDate? 
An exception has been avoided for now. 
A few of these errors are going to be reported with this complaint, then further  violations will simply silently do whatever random thing results from the nil. 
Here is the backtrace where this occurred this time (some frames may be missing due to  compiler optimizations): 
(
0 CoreFoundation      0x37a1d78f <redacted> + 86 
1 Portfolio       0x000a0d1f -[ECGraph(Private) getDaysFrom:To:] + 202 
2 Portfolio       0x000a1577 -[ECGraph(Private) getXDaysFromLines:minDate:] + 502 
3 Portfolio       0x000a2623 -[ECGraph drawCurveWithLines:lineWidth:color:] + 978 
4 Portfolio       0x000a716f -[GraphView drawRect:] + 2682 
5 UIKit        0x38b1811d <redacted> + 364 
6 QuartzCore       0x39468035 <redacted> + 112 
7 QuartzCore       0x39467771 <redacted> + 1808 
8 QuartzCore       0x39466f45 <redacted> + 980 
9 QuartzCore       0x39466a7b <redacted> + 202 
10 QuartzCore       0x3953a9f5 <redacted> + 24 
11 QuartzCore       0x394663d3 <redacted> + 238 
12 QuartzCore       0x39466119 <redacted> + 316 
13 QuartzCore       0x3945dfe1 <redacted> + 60 
14 CoreFoundation      0x37a4f18d <redacted> + 20 
15 CoreFoundation      0x37a4d3f9 <redacted> + 276 
16 CoreFoundation      0x37a4d74f <redacted> + 742 
17 CoreFoundation      0x379cbc1d CFRunLoopRunSpecific + 356 
18 CoreFoundation      0x379cbaa9 CFRunLoopRunInMode + 104 
19 GraphicsServices     0x3a88f33b GSEventRunModal + 74 
20 UIKit        0x38b35535 UIApplicationMain + 1120 
21 Portfolio       0x00094e7d main + 152 
22 Portfolio       0x00094de0 start + 40 

+0

我有完全相同的問題。你有沒有發現它?真是小錯誤也。我正在使用NSDateFormatter將字符串轉換爲日期,然後使用NSUInteger desiredComponents和NSDateComponents * elapsedTimeUnits將其轉換爲顯示它多久之前。 「我的意思是,你認爲......」,哈哈! – Sti

+0

玩弄設備上的數據和時間設置,這對我很有用。然後,我在代碼中更改了它們,使其全部本地化。 – JH95

回答

3

你試圖讓從零NSDate的那樣NSDateComponents:

NSCalendar* gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
NSDate* fromDate = nil; 
NSDate* toDate = [NSDate date]; 
unsigned int components = NSYearCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit; 
NSDateComponents* dateComponents = [gregorian components:uintFlags fromDate:fromDate toDate:toDate options:0]; 

可能是一個簡單的檢查,可能是有用的:

NSDate* fromDate = nil; 
NSDate* toDate = [NSDate date]; 

NSDateComponents* dateComponents = nil; 

if(fromDate != nil) 
{ 
NSCalendar* gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
unsigned int components = NSYearCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit; 
dateComponents = [gregorian components:uintFlags fromDate:fromDate toDate:toDate options:0]; 
} 
1

您的設備正在使用與您的模擬器不同的區域格式。

如果你匹配那些(在Settings -> General -> International),那麼他們應該顯示相同的結果。在我的情況下,這樣做時,他們都失敗了,但模擬器沒有給出與設備相同的日誌,所以我幾乎錯過了它。

我假設您正在使用NSDateFormatter將一些字符串日期格式化爲NSDate。在這種情況下,您必須確保這不會取決於手機的類型,並將解決方案永遠保持相同,無論您身在何處。

[df setLocale:([[NSLocale alloc] initWithLocaleIdentifier:@"en_UK"])]; 
// df being the NSDateFormatter-object 

這告訴格式化程序使用英國標準格式,這在我的情況下是需要的。輸入您需要的國家代碼,即en_US

性病

+0

我沒有使用NSDataFormatter來格式化字符串,我還能怎麼做呢? – JH95

+0

@JakeHoskins - 我確定有很多方法可以解決這個問題,但是如果沒有看到一些代碼,我什麼也不能說。編輯您的問題以包含使用'fromDate'的方法。 – Sti

相關問題