NSCalendar 崩溃应用程序
我正在 viewDidLoad 中初始化 NSCalendar,如下所示:
gregorian = [NSCalendar currentCalendar];
日历在相应的 .h 文件中声明如下:
NSCalendar *gregorian;
当从方法访问日历时,我的应用程序崩溃:
- (void)someMethod{
unsigned int unitFlags;
unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit;
[gregorian
components:unitFlags
fromDate:[NSDate date]
toDate:[NSDate date]
options:0];
}
这是从崩溃日志中看来相关的内容:
类型:EXC_BAD_ACCESS (SIGBUS)
异常代码:KERN_PROTECTION_FAILURE 位于 0x0000000000000015
崩溃线程:0 调度队列:com.apple.main-thread
应用程序特定信息:
objc_msgSend() 选择器名称:组件:fromDate:toDate:选项:
iPhone 模拟器 225、iPhone OS 3.2 (iPad/7W367a)
有什么想法吗?
谢谢
I'm initializing a NSCalendar in viewDidLoad like this:
gregorian = [NSCalendar currentCalendar];
The calendar is declared in the corresponding .h file like this:
NSCalendar *gregorian;
When accessing the calendar from a method my app crashes:
- (void)someMethod{
unsigned int unitFlags;
unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit;
[gregorian
components:unitFlags
fromDate:[NSDate date]
toDate:[NSDate date]
options:0];
}
This is what seems relevant from the crash log:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000015
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Application Specific Information:
objc_msgSend() selector name: components:fromDate:toDate:options:
iPhone Simulator 225, iPhone OS 3.2 (iPad/7W367a)
Any ideas ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将日历分配给“公历”时,您不会保留日历,因此当您访问它时它就消失了。
You're not retaining your calendar when assigning it to "gregorian" so it is gone by the time you access it.