Undefined key NSException in UIPickerView iOS7.1

那年仲夏 提交于 2019-12-10 19:55:52

问题


I'm getting an exception in the iOS 7.1 simulator that doesn't appear in 7.0. It appears to be handled somewhere in the core because it only triggers an exception raise breakpoint. It doesn't log to the console or crash. This occurs while scrolling through options in a UIPickerView. There is no meaningful backtrace available (right from UIApplicationMain into objc_exception_throw), but examining the exception during throw in the debugger shows:

[<UIPickerView 0xb9a6700> valueForUndefinedKey:]: this class is not key value coding-compliant for the key _mode.

I searched in my project for mode, setMode:, mode = but I don't think I'm the one setting this. Anyone else run into this? I guess it's okay if it's not crashing the app but it gave me a scare, and I'd rather take action to prevent it from being thrown. If I have some more time I'll try to isolate this in a test project and follow up.

Edit: Better backtrace:

         thread #1: tid = 0x10975c, 0x02590909 libc++abi.dylib`__cxa_throw, queue = 'com.apple.main-thread, stop reason = breakpoint 1.2
     frame #0: 0x02590909 libc++abi.dylib`__cxa_throw
     frame #1: 0x01b1d9fc libobjc.A.dylib`objc_exception_throw + 323
     frame #2: 0x020e1fe1 CoreFoundation`-[NSException raise] + 17
     frame #3: 0x017ddc7a Foundation`-[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 282
     frame #4: 0x0174adfd Foundation`_NSGetUsingKeyValueGetter + 81
     frame #5: 0x0174a437 Foundation`-[NSObject(NSKeyValueCoding) valueForKey:] + 260
     frame #6: 0x0d615dff AccessibilityUtilities`-[NSObject(UIAccessibilitySafeCategory) safeValueForKey:] + 43
     frame #7: 0x1151c1f6 UIKit`-[UIAccessibilityPickerComponent accessibilityTraits] + 398
     frame #8: 0x0d716021 UIAccessibility`-[NSObject(AXPrivCategory) accessibilityAttributeValue:] + 1865
     frame #9: 0x0d70a7d7 UIAccessibility`_copyMultipleAttributeValuesCallback + 409
     frame #10: 0x0d76c537 AXRuntime`_AXXMIGCopyMultipleAttributeValues + 202
     frame #11: 0x0d767e78 AXRuntime`_XCopyMultipleAttributeValues + 473
     frame #12: 0x0d7726b4 AXRuntime`mshMIGPerform + 256
     frame #13: 0x01fcdca5 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
     frame #14: 0x01fcd9db CoreFoundation`__CFRunLoopDoSource1 + 523
     frame #15: 0x01ff868c CoreFoundation`__CFRunLoopRun + 2156
     frame #16: 0x01ff79d3 CoreFoundation`CFRunLoopRunSpecific + 467
     frame #17: 0x01ff77eb CoreFoundation`CFRunLoopRunInMode + 123
     frame #18: 0x03fea5ee GraphicsServices`GSEventRunModal + 192
     frame #19: 0x03fea42b GraphicsServices`GSEventRun + 104
     frame #20: 0x007ddf9b UIKit`UIApplicationMain + 1225
     frame #21: 0x0004863d [redacted]`main(argc=1, argv=0xbfffef50) + 141 at main.m:16

回答1:


In my case, on Xcode 6.2 and iOS 8.2, only simulator crashes (but can safely continue). Since _mode is nowhere within our code, it's probably safe to assume there is a simulator bug or misconfiguration.

For now, I am using a category on the offending UIPickerView to get rid of the annoyance:

#import "UIPickerView+FixCrash.h"

@implementation UIPickerView (FixCrash)

#if TARGET_IPHONE_SIMULATOR
- (id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}
#endif

@end


来源:https://stackoverflow.com/questions/22697817/undefined-key-nsexception-in-uipickerview-ios7-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!