简体   繁体   English

ECGraph不在设备上工作,但在模拟器上工作

[英]ECGraph not working on device, but works on simulator

is there any reason why ECGraph would run fine on the simulator, but yet give me this error when i run it on my device: 有什么理由说为什么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

)

You are trying to get NSDateComponents from a nil NSDate like that: 你试图从这样的nil 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];

Probably a simple check can be useful: 可能一个简单的检查可能是有用的:

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];
}

Your device is using a different Region Format than your simulator. 您的设备使用的区域格式与模拟器不同。

If you match those (in Settings -> General -> International ), then they should show the same result. 如果你匹配(在Settings -> General -> International ),那么他们应该显示相同的结果。 In my case, when doing this, they both failed, but the simulator didn't give the same log as the device so I nearly missed it. 在我的情况下,当这样做时,他们都失败了,但模拟器没有提供与设备相同的日志,所以我几乎错过了它。

I assume you are using an NSDateFormatter to format some string-date to NSDate as I was. 我假设您正在使用NSDateFormatter将某些字符串日期格式化为NSDate。 In that case you have to make sure that this won't depend on what kind of region the phone is, and set the solution to always be the same, whereever you are. 在这种情况下,您必须确保这不取决于手机的区域类型,并将解决方案设置为始终相同,无论您是谁。

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

This tells the formatter to format using UK standards, which was needed in my case. 这告诉格式化程序使用英国标准进行格式化,这在我的案例中是必需的。 Enter your needed country code, ie en_US etc. 输入您需要的国家代码,即en_US等。

Sti 性病

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GetViewForHeader可在模拟器中工作,但不能在设备上工作 - GetViewForHeader works in the simulator but not working on the device iOS Webkit不在设备上工作,但在swift的模拟器上运行 - iOS Webkit not working on device, but works on simulator at swift AVPlayer在模拟器上运行,但不在设备上运行 - AVPlayer Works on Simulator, but not on device 应用程序适用于模拟器但不适用于设备 - App works on simulator but not on device 并发症只能在模拟器上使用,而不能在设备上使用 - Complication works on Simulator, but not on Device ASIFormDataRequest在模拟器上工作但在设备上不工作? - ASIFormDataRequest works on simulator but not on device? CCTMXTileMap可在模拟器上使用,但不能在设备上使用 - CCTMXTileMap works on simulator but not on device 代码适用于模拟器但不适用于设备 - Code works on simulator but not on device Parse.com Facebook登录屏幕无法在设备上使用,但可以在模拟器上使用 - Parse.com Facebook Sign In Screen not working on device, but works on simulator 使用主机应用程序与自定义键盘扩展进行通信,但无法在设备中运行,但可在模拟器中运行 - Communicate with Custom Keyboard extension with Host App not working in device but works in simulator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM