0

我有以下代码在更改 UISwitcher 时执行:

if(switcher.on == YES) {
    self.pickerView.datePickerMode = UIDatePickerModeDate;
}
else {
    self.pickerView.datePickerMode = UIDatePickerModeTime;
}

这会导致应用程序在模拟器中崩溃,并带有以下堆栈跟踪:

* thread #1: tid = 0x1f03, 0x027997dc CoreFoundation`CFNumberGetValue + 12, stop reason = EXC_BAD_ACCESS (code=2, address=0xbf7fffec)
frame #0: 0x027997dc CoreFoundation`CFNumberGetValue + 12
frame #1: 0x02843d2c CoreFoundation`-[__NSCFNumber longValue] + 76
frame #2: 0x02843ed1 CoreFoundation`-[__NSCFNumber integerValue] + 33
frame #3: 0x0a624255 UIKit`-[UIPickerViewAccessibility(SafeCategory) accessibilityContainerElements] + 99
frame #4: 0x08f61424 UIAccessibility`-[NSObject(AXPrivCategory) accessibilityElementCount] + 34
frame #5: 0x08f6135b UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityResetContainerElements] + 75

...

frame #196418: 0x08f6135b UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityResetContainerElements] + 75
frame #196419: 0x0a624290 UIKit`-[UIPickerViewAccessibility(SafeCategory) accessibilityContainerElements] + 158
frame #196420: 0x08f61424 UIAccessibility`-[NSObject(AXPrivCategory) accessibilityElementCount] + 34
frame #196421: 0x08f6135b UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityResetContainerElements] + 75
frame #196422: 0x0a624290 UIKit`-[UIPickerViewAccessibility(SafeCategory) accessibilityContainerElements] + 158
frame #196423: 0x08f61424 UIAccessibility`-[NSObject(AXPrivCategory) accessibilityElementCount] + 34
frame #196424: 0x08f6135b UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityResetContainerElements] + 75
frame #196425: 0x0a624465 UIKit`-[UIPickerViewAccessibility(SafeCategory) reloadAllComponents] + 68
frame #196426: 0x00ca8b18 UIKit`-[UIDatePickerView _updateBitsForDate:forced:andReload:animateIfNeeded:] + 611
frame #196427: 0x00ca9116 UIKit`-[UIDatePickerView _setDate:animated:forced:] + 372
frame #196428: 0x00caa13b UIKit`-[UIDatePickerView setDatePickerMode:] + 535
frame #196429: 0x00ca7669 UIKit`-[UIDatePicker setDatePickerMode:] + 51
frame #196430: 0x0005ba9b MyApp`-[RRDatePickerViewController switchChanged:] + 283 at RRDatePickerViewController.m:249
frame #196431: 0x02876e99 CoreFoundation`-[NSObject performSelector:withObject:withObject:] + 73
frame #196432: 0x00aa914e UIKit`-[UIApplication sendAction:to:from:forEvent:] + 96
frame #196433: 0x00aa90e6 UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
frame #196434: 0x00b4fade UIKit`-[UIControl sendAction:to:forEvent:] + 66
frame #196435: 0x00b4ffa7 UIKit`-[UIControl(Internal) _sendActionsForEvents:withEvent:] + 503
frame #196436: 0x00ca3c16 UIKit`-[_UISwitchInternalView _sendActions] + 121
frame #196437: 0x013cc85d Foundation`__NSFireDelayedPerform + 389
frame #196438: 0x02849936 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
frame #196439: 0x028493d7 CoreFoundation`__CFRunLoopDoTimer + 551
frame #196440: 0x027ac790 CoreFoundation`__CFRunLoopRun + 1888
frame #196441: 0x027abd84 CoreFoundation`CFRunLoopRunSpecific + 212
frame #196442: 0x027abc9b CoreFoundation`CFRunLoopRunInMode + 123
frame #196443: 0x02cf97d8 GraphicsServices`GSEventRunModal + 190
frame #196444: 0x02cf988a GraphicsServices`GSEventRun + 103
frame #196445: 0x00aa6626 UIKit`UIApplicationMain + 1163
frame #196446: 0x00002732 MyApp`main + 130 at main.m:16
frame #196447: 0x000026a5 MyApp`start + 53

有人对为什么会发生这种情况有任何建议吗?谢谢。

干杯,加兹。

4

1 回答 1

0

这似乎与这里的问题相同

一个用于多个字段的 UIDatePicker - 设置日期时的 EXC_BAD_ACCESS

在 iPhone 上运行代码时不会出现此问题。

于 2012-08-16T09:03:53.880 回答