此类不是密钥值的密钥值编码兼容。 UISearchBar和DisplayController
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了此类不是密钥值的密钥值编码兼容。 UISearchBar和DisplayController相关的知识,希望对你有一定的参考价值。
我正在制作一个使用UITableViewController的应用程序,我正在尝试添加一个UISearchBarWithDisplayController。 (我正在使用本教程:http://www.appcoda.com/search-bar-tutorial-ios7/)。我按照所有步骤操作,但是当我在搜索视图中按键盘上的字母时,应用程序崩溃,我收到此错误:
2014-05-28 19:11:03.850 Williams[1353:60b] *** Terminating app due to
uncaught exception 'NSUnknownKeyException', reason:
'[<__NSCFConstantString 0x100219d80> valueForUndefinedKey:]: this
class is not key value coding-compliant for the key name.'
*** First throw call stack: (0x186b8a950 0x1930901fc 0x186b8a5d4 0x1876db618 0x187624bdc 0x18766d8e8 0x18766d3d0 0x18766c1d4
0x18766c150 0x18766bf28 0x100038904 0x100038af8 0x189d6c558
0x189b890e8 0x189b8905c 0x189b72538 0x189d6c264 0x189b93a64
0x189d27a7c 0x189d26dfc 0x189d26ae4 0x187634a20 0x189b97e58
0x189d269ac 0x189b7d2f0 0x18770c5cc 0x186b4b044 0x186b4a3a0
0x186b48638 0x186a896d0 0x18c76dc0c 0x189bbafdc 0x10003970c
0x193683aa0) libc++abi.dylib: terminating with uncaught exception of
type NSException
当我按下键盘上的一个字母并且像这样卡住时它会崩溃:
还有一点很奇怪的是,如果我在ios模拟器中崩溃,它会给我一个不同的崩溃报告:
2014-05-28 19:25:33.490 Williams[6847:60b] *** Terminating app due to
uncaught exception 'NSUnknownKeyException', reason:
'[<__NSCFConstantString 0x1002091f8> valueForUndefinedKey:]: this
class is not key value coding-compliant for the key name.'
*** First throw call stack: ( 0 CoreFoundation 0x0000000102a6d495 __exceptionPreprocess + 165 1 libobjc.A.dylib
0x00000001027cc99e objc_exception_throw + 43 2 CoreFoundation
0x0000000102af1919 -[NSException raise] + 9 3 Foundation
0x00000001024313c6 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:]
+ 226 4 Foundation 0x00000001023ae155 -[NSObject(NSKeyValueCoding) valueForKey:] + 251 5 Foundation 0x0000000102383922 -[NSFunctionExpression
expressionValueWithObject:context:] + 1003 6 Foundation
0x00000001023fbbd0 -[NSComparisonPredicate
evaluateWithObject:substitutionVariables:] + 236 7 Foundation
0x00000001023fbae2 -[NSPredicate evaluateWithObject:] + 19 8
Foundation 0x00000001023fba7d
_filterObjectsUsingPredicate + 353 9 Foundation 0x00000001023fb89a -[NSArray(NSPredicateSupport)
filteredArrayUsingPredicate:] + 286 10 Williams
0x000000010000ede2 -[StaffTVC filterContentForSearchText:scope:] + 162
11 Williams 0x000000010000ef8c -[StaffTVC
searchDisplayController:shouldReloadTableForSearchString:] + 316 12
UIKit 0x00000001016c286e
-[UISearchDisplayController searchBar:textDidChange:] + 126 13 UIKit 0x000000010137af1e -[UIApplication sendAction:to:from:forEvent:] + 104
14 UIKit 0x000000010137aeb4
-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17 15 UIKit 0x0000000101457880 -[UIControl
_sendActionsForEvents:withEvent:] + 203 16 UIKit 0x00000001019bfe84 -[UITextField fieldEditorDidChange:] + 198 17
UIKit 0x00000001019cbb97
-[UITextInputController _sendDelegateChangeNotificationsForText:selection:] + 102 18 UIKit 0x00000001019cd670 -[UITextInputController _insertText:fromKeyboard:]
+ 651 19 UIKit 0x00000001019cdddc -[UITextInputController insertText:] + 301 20 UIKit 0x0000000101523e00 -[UIKeyboardImpl insertText:] + 82 21 Foundation
0x0000000102442d34 -[__NSOperationInternal _start:] + 623 22 UIKit
0x0000000101522827 -[UIKeyboardImpl performOperations:] + 148 23
UIKit 0x0000000101520e17
__73-[UIKeyboardImpl replyHandlerForHandleKeyboardInputWithExecutionContext:]_block_invoke_2
+ 40 24 UIKit 0x00000001019e35c6 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 329 25 UIKit 0x000000010152f4ff -[UIKeyboardImpl handleKeyEvent:] + 220 26 UIKit
0x0000000101375f8e _UIApplicationHandleEventQueue + 2572 27
CoreFoundation 0x00000001029fcd21
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 28 CoreFoundation 0x00000001029fc6b9
__CFRunLoopDoSources0 + 441 29 CoreFoundation 0x0000000102a1846f __CFRunLoopRun + 767 30 CoreFoundation
0x0000000102a17d83 CFRunLoopRunSpecific + 467 31 GraphicsServices
0x000000010374ff04 GSEventRunModal + 161 32 UIKit
0x0000000101379e33 UIApplicationMain + 1010 33 Williams
0x0000000100010743 main + 115 34 libdyld.dylib
0x00000001070575fd start + 1 35 ???
0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with
uncaught exception of type NSException
答案
试试这个:
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"self contains[c] %@", searchText];
需要使用“自我”,而不是“名字”
以上是关于此类不是密钥值的密钥值编码兼容。 UISearchBar和DisplayController的主要内容,如果未能解决你的问题,请参考以下文章
错误:由于未捕获的异常'NSUnknownKeyException'而终止应用,原因:'[ 的setValue:forUndefinedKey:]
我该如何修复此警告信息。警告:忽略“UIButton”实例上的键路径“radius”的用户定义的运行时属性
未捕获的异常 'NSUnknownKeyException' - 此类与键 buttonPressed 的键值编码不兼容