2015-08-17 06:18:50.281 testcrash WatchKit Extension[1050:29694] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<InterfaceController 0x7d248f80> valueForUndefinedKey:]: this class is not key value coding-compliant for the key (null).'
*** First throw call stack:
(
0 CoreFoundation 0x02f882c4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00682df4 objc_exception_throw + 50
2 CoreFoundation 0x02f87ee1 -[NSException raise] + 17
3 Foundation 0x002c4696 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 282
4 Foundation 0x00205870 _NSGetUsingKeyValueGetter + 105
5 Foundation 0x002057ff -[NSObject(NSKeyValueCoding) valueForKey:] + 288
6 WatchKit 0x0014d454 __48-[SPRemoteInterface handlePlist:fromIdentifier:]_block_invoke905 + 46
7 libdispatch.dylib 0x03db8837 _dispatch_call_block_and_release + 15
8 libdispatch.dylib 0x03dd641d _dispatch_client_callout + 14
9 libdispatch.dylib 0x03dbf0da _dispatch_main_queue_callback_4CF + 689
10 CoreFoundation 0x02eda46e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
11 CoreFoundation 0x02e981e4 __CFRunLoopRun + 2356
12 CoreFoundation 0x02e975f6 CFRunLoopRunSpecific + 470
13 CoreFoundation 0x02e9740b CFRunLoopRunInMode + 123
14 Foundation 0x00241e11 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 308
15 Foundation 0x002e7f6d -[NSRunLoop(NSRunLoop) run] + 82
16 libxpc.dylib 0x040d30c7 _xpc_objc_main + 486
17 libxpc.dylib 0x040d5e26 xpc_main + 215
18 Foundation 0x00410fb5 service_connection_handler + 0
19 PlugInKit 0x02e001f4 -[PKService run] + 582
20 WatchKit 0x00171509 main + 146
21 libdyld.dylib 0x03dfbae1 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
我用一个干净的新项目来解决这个问题。将WKPicker拖入故事板并尝试模拟该程序。
(原生watchos2 app)
答案 0 :(得分:0)
这里的问题似乎是选择器保持空白。
var foodList: [(String, String)] = [
("Broccoli", "Gross"),
("Brussel Sprouts", "Gross"),
("Soup", "Delicious"),
("Steak", "Delicious"),
("Ramen", "Delicious"),
("Pizza", "Delicious") ]
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
let pickerItems: [WKPickerItem] = foodList.map {
let pickerItem = WKPickerItem()
pickerItem.title = $0.0
pickerItem.caption = $0.1
return pickerItem
}
serverPicker.setItems(pickerItems)
}
解决了这个问题。
复制自:http://www.sneakycrab.com/blog/2015/6/12/wkinterfacepicker-in-watchkit-20-using-the-digital-crown