NSInvalidArgumentException:无法识别的选择器发送到实例|迅速

时间:2015-02-27 21:27:00

标签: ios swift keyboard

我意识到这个问题已被多次提出,但它似乎是由许多不同的事情引起的,并且非常具有情境性。

我的追踪:

2015-02-27 16:20:06.289 RTApp[43486:1122681] -[RTApp.conversationVC keyboardWasShown]: unrecognized selector sent to instance 0x7f866a766830
2015-02-27 16:20:06.291 RTApp[43486:1122681] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RTApp.conversationVC keyboardWasShown]: unrecognized selector sent to instance 0x7f866a766830'
*** First throw call stack:
(
0   CoreFoundation                      0x00000001071b8f35 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x0000000106e51bb7 objc_exception_throw + 45
2   CoreFoundation                      0x00000001071c004d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x000000010711827c ___forwarding___ + 988
4   CoreFoundation                      0x0000000107117e18 _CF_forwarding_prep_0 + 120
5   CoreFoundation                      0x0000000107188cec __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
6   CoreFoundation                      0x00000001070888a4 _CFXNotificationPost + 2484
7   Foundation                          0x00000001069af6b8 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
8   UIKit                               0x0000000107c75eb8 -[UIInputWindowController postEndNotifications:withInfo:] + 527
9   UIKit                               0x0000000107c77725 __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke572 + 354
10  UIKit                               0x0000000107617113 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 326
11  UIKit                               0x00000001075fee6a -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 209
12  UIKit                               0x00000001075ff1a0 -[UIViewAnimationState animationDidStop:finished:] + 76
13  QuartzCore                          0x0000000105c4c7ee _ZN2CA5Layer23run_animation_callbacksEPv + 308
14  libdispatch.dylib                   0x0000000108de57f4 _dispatch_client_callout + 8
15  libdispatch.dylib                   0x0000000108dce8fb _dispatch_main_queue_callback_4CF + 949
16  CoreFoundation                      0x0000000107120fe9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
17  CoreFoundation                      0x00000001070e3eeb __CFRunLoopRun + 2043
18  CoreFoundation                      0x00000001070e3486 CFRunLoopRunSpecific + 470
19  GraphicsServices                    0x000000010aa0f9f0 GSEventRunModal + 161
20  UIKit                               0x00000001075a5420 UIApplicationMain + 1282
21  RTApp                               0x000000010563623e top_level_code + 78
22  RTApp                               0x000000010563627a main + 42
23  libdyld.dylib                       0x0000000108e1a145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

有问题的功能:

func keyboardWasShown(notification: NSNotification){

    let dict:NSDictionary = notification.userInfo!
    let s:NSValue = dict.valueForKey(UIKeyboardFrameEndUserInfoKey) as NSValue
    let rect:CGRect = s.CGRectValue()

    UIView.animateWithDuration(0.3, delay: 0, options: .CurveLinear, animations: {
        self.resultsScrollView.frame.origin.y = self.scrollViewOriginalY - rect.height
        self.frameMessageView.frame.origin.y = self.frameMessageOriginalY - rect.height

        var bottomOffset:CGPoint = CGPointMake(0, self.resultsScrollView.contentSize.height - self.resultsScrollView.bounds.size.height)
        self.resultsScrollView.setContentOffset(bottomOffset, animated: false)

        }, completion: {
            (finished:Bool) in
    })
}

所以这应该只是推动视图,因此键入时键盘不会覆盖它。但是一旦我拉起键盘,它就会崩溃。如果Xcode告诉你错误是哪一行会很好,但这太容易了。

这是否意味着该功能无法识别我传入的参数?或者为什么它无法识别'选择器'?

1 个答案:

答案 0 :(得分:5)

根据错误消息reason: '-[RTApp.conversationVC keyboardWasShown]: unrecognized selector判断您在添加通知观察者时使用了错误的选择器。

您应该使用Selector("keyboardWasShown:")代替Selector("keyboardWasShown"),因为您的方法有一个参数。