当前位置:  开发笔记 > 前端 > 正文

[NSNull length]:无法识别的选择器在键盘按键上发送到实例?

如何解决《[NSNulllength]:无法识别的选择器在键盘按键上发送到实例?》经验,为你挑选了1个好方法。

我在静态表视图中添加了一些textFieldtextView.代码很好,并运行在xcode 6.4/ios 8.*但它抛出异常,我无法跟踪.现在我在xcode 7.2上调试代码(swift2.2)

我尝试过设置符号特殊的断点,但没有运气:(

以下是崩溃的堆栈跟踪,提前感谢您的宝贵帮助.

2015-12-14 16:07:07.989 TuteMate[3380:90711] -[NSNull length]: unrecognized selector sent to instance 0x10ccc6af0 

从特殊的断点:

CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:]:
->  0x10504e3c0 <+0>:   pushq  %rbp
    0x10504e3c1 <+1>:   movq   %rsp, %rbp
    0x10504e3c4 <+4>:   pushq  %r15
    0x10504e3c6 <+6>:   pushq  %r14
    0x10504e3c8 <+8>:   pushq  %rbx
    0x10504e3c9 <+9>:   pushq  %rax
    0x10504e3ca <+10>:  movq   %rdx, %r14
    0x10504e3cd <+13>:  movq   %rdi, %rbx
    0x10504e3d0 <+16>:  movq   0x216c79(%rip), %rsi      ; "class"
    0x10504e3d7 <+23>:  callq  *0x229e1b(%rip)           ; (void *)0x000000010730b800: objc_msgSend
    0x10504e3dd <+29>:  movq   %rax, %rdi
    0x10504e3e0 <+32>:  movq   %rbx, %rsi
    0x10504e3e3 <+35>:  movq   %r14, %rdx
    0x10504e3e6 <+38>:  callq  0x10504ed00               ; __CFFullMethodName
    0x10504e3eb <+43>:  movq   %rax, %r14
    0x10504e3ee <+46>:  leaq   0x23fdeb(%rip), %r15      ; @"%@: unrecognized selector sent to instance %p"
    0x10504e3f5 <+53>:  movl   $0x3, %edi
    0x10504e3fa <+58>:  xorl   %eax, %eax
    0x10504e3fc <+60>:  movq   %r15, %rsi
    0x10504e3ff <+63>:  movq   %r14, %rdx
    0x10504e402 <+66>:  movq   %rbx, %rcx
    0x10504e405 <+69>:  callq  0x104fe2560               ; CFLog
    0x10504e40a <+74>:  leaq   0x22b90f(%rip), %rax      ; kCFAllocatorSystemDefault
    0x10504e411 <+81>:  movq   (%rax), %rdi
    0x10504e414 <+84>:  xorl   %esi, %esi
    0x10504e416 <+86>:  xorl   %eax, %eax
    0x10504e418 <+88>:  movq   %r15, %rdx
    0x10504e41b <+91>:  movq   %r14, %rcx
    0x10504e41e <+94>:  movq   %rbx, %r8
    0x10504e421 <+97>:  callq  0x104f35190               ; CFStringCreateWithFormat
    0x10504e426 <+102>: movq   %rax, %rdi
    0x10504e429 <+105>: callq  0x104f33580               ; CFMakeCollectable
    0x10504e42e <+110>: movq   %rax, %rbx
    0x10504e431 <+113>: movq   %rbx, %rdi
    0x10504e434 <+116>: nop    
    0x10504e435 <+117>: nopl   (%rax)
    0x10504e439 <+121>: leaq   0x225300(%rip), %rax      ; __CFOASafe
    0x10504e440 <+128>: cmpb   $0x0, (%rax)
    0x10504e443 <+131>: je     0x10504e459               ; <+153>
    0x10504e445 <+133>: movl   $0x3, %edi
    0x10504e44a <+138>: xorl   %edx, %edx
    0x10504e44c <+140>: xorl   %ecx, %ecx
    0x10504e44e <+142>: xorl   %r8d, %r8d
    0x10504e451 <+145>: movq   %rbx, %rsi
    0x10504e454 <+148>: callq  0x10501b150               ; __CFRecordAllocationEvent
    0x10504e459 <+153>: movq   %rbx, %rdi
    0x10504e45c <+156>: callq  0x1050a3696               ; symbol stub for: _objc_rootAutorelease
    0x10504e461 <+161>: movq   0x218370(%rip), %rdi      ; (void *)0x00000001052690d0: NSException
    0x10504e468 <+168>: leaq   0x234fb1(%rip), %rcx      ; NSInvalidArgumentException
    0x10504e46f <+175>: movq   (%rcx), %rdx
    0x10504e472 <+178>: movq   0x216c4f(%rip), %rsi      ; "exceptionWithName:reason:userInfo:"
    0x10504e479 <+185>: xorl   %r8d, %r8d
    0x10504e47c <+188>: movq   %rax, %rcx
    0x10504e47f <+191>: callq  *0x229d73(%rip)           ; (void *)0x000000010730b800: objc_msgSend
    0x10504e485 <+197>: movq   %rax, %rdi
    0x10504e488 <+200>: callq  0x1050a3738               ; symbol stub for: objc_exception_throw
    0x10504e48d <+205>: nopl   (%rax)

更新堆栈跟踪

2015-12-14 16:45:58.932 TuteMate[4000:109943] -[NSNull length]: unrecognized selector sent to instance 0x105b72af0
2015-12-14 16:46:02.651 TuteMate[4000:109943] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x105b72af0'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010594de65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000107bfddeb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010595648d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00000001058a390a ___forwarding___ + 970
    4   CoreFoundation                      0x00000001058a34b8 _CF_forwarding_prep_0 + 120
    5   CoreFoundation                      0x0000000105825dfa CFStringCompareWithOptionsAndLocale + 202
    6   Foundation                          0x0000000106019e37 -[NSString compare:options:range:] + 29
    7   UIKit                               0x00000001069c4e6f -[UIPhysicalKeyboardEvent _matchesKeyCommand:] + 303
    8   UIKit                               0x00000001068e93fd -[UIResponder _keyCommandForEvent:target:] + 364
    9   UIKit                               0x00000001068e95b2 -[UIResponder _keyCommandForEvent:target:] + 801
    10  UIKit                               0x00000001068e95b2 -[UIResponder _keyCommandForEvent:target:] + 801
    11  UIKit                               0x00000001068e95b2 -[UIResponder _keyCommandForEvent:target:] + 801
    12  UIKit                               0x00000001068e95b2 -[UIResponder _keyCommandForEvent:target:] + 801
    13  UIKit                               0x00000001068e95b2 -[UIResponder _keyCommandForEvent:target:] + 801
    14  UIKit                               0x00000001068e95b2 -[UIResponder _keyCommandForEvent:target:] + 801
    15  UIKit                               0x00000001066fb91a -[UIApplication _handleKeyUIEvent:] + 948
    16  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    17  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    18  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    19  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    20  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    21  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    22  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    23  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    24  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    25  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    26  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    27  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    28  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    29  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    30  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    31  UIKit                               0x00000001068e9e53 -[UIResponder _handleKeyUIEvent:] + 79
    32  UIKit                               0x00000001066fb2cd -[UIApplication handleKeyUIEvent:] + 79
    33  UIKit                               0x0000000106991c83 -[UIKeyboardImpl _handleKeyEvent:executionContext:] + 66
    34  UIKit                               0x0000000106b91cde -[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:] + 3356
    35  UIKit                               0x00000001069a0bbd __28-[UIKeyboardLayout touchUp:]_block_invoke + 228
    36  UIKit                               0x00000001070ed724 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 332
    37  UIKit                               0x00000001069a0ace -[UIKeyboardLayout touchUp:] + 236
    38  UIKit                               0x00000001069a1614 -[UIKeyboardLayout touchesEnded:withEvent:] + 348
    39  UIKit                               0x000000010674b49b -[UIWindow _sendTouchesForEvent:] + 835
    40  UIKit                               0x000000010674c1d0 -[UIWindow sendEvent:] + 865
    41  UIKit                               0x00000001066fab66 -[UIApplication sendEvent:] + 263
    42  UIKit                               0x00000001066d4d97 _UIApplicationHandleEventQueue + 6844
    43  CoreFoundation                      0x0000000105879a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    44  CoreFoundation                      0x000000010586f95c __CFRunLoopDoSources0 + 556
    45  CoreFoundation                      0x000000010586ee13 __CFRunLoopRun + 867
    46  CoreFoundation                      0x000000010586e828 CFRunLoopRunSpecific + 488
    47  GraphicsServices                    0x000000010c9daad2 GSEventRunModal + 161
    48  UIKit                               0x00000001066da610 UIApplicationMain + 171
    49  TuteMate                            0x000000010500128d main + 109
    50  libdyld.dylib                       0x000000010932c92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException 

更新 没有其他viewWillAppeaer,didAppear ...方法实现!

override func viewDidLoad() {
            super.viewDidLoad()
            title = "Profile Edit"
           }

并且表viewDelegates是

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 3
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath)
    return cell
}

gnasher729.. 5

@dip:从您的评论中看来,您需要学习一些非常重要的调试方法,那就是:您认为的一切都是错误的.当你说"我不存储null或类似的东西"时,我们知道这是错误的.第二个最重要的规则:相信证据.

证据是消息"length:"是一个NSString方法被发送到[NSNull null].你存储[NSNull null]的某个地方你应该存储一个字符串.第三条调试规则:做错了什么.没有神秘的小鬼试图让你心烦意乱,这是你的代码错了.因此,找出存储[NSNull null]的位置.来自JSON解析器的任何东西总是一个很好的候选者.



1> gnasher729..:

@dip:从您的评论中看来,您需要学习一些非常重要的调试方法,那就是:您认为的一切都是错误的.当你说"我不存储null或类似的东西"时,我们知道这是错误的.第二个最重要的规则:相信证据.

证据是消息"length:"是一个NSString方法被发送到[NSNull null].你存储[NSNull null]的某个地方你应该存储一个字符串.第三条调试规则:做错了什么.没有神秘的小鬼试图让你心烦意乱,这是你的代码错了.因此,找出存储[NSNull null]的位置.来自JSON解析器的任何东西总是一个很好的候选者.

推荐阅读
mobiledu2402851203
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有