每当我点击以编程方式添加到视图中的UITextField时,我的应用都会崩溃。这是堆栈跟踪(如果有帮助的话):

'NSInvalidArgumentException', reason: '-[Clifford_Bradford.OtherVehiclesViewController numOfOtherVehiclesUpdated:]: unrecognized selector sent to instance 0x7fd92a57f8d0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000107e5dc65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001099c8bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000107e650ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000107dbb13c ___forwarding___ + 988
    4   CoreFoundation                      0x0000000107dbacd8 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x00000001086fdd62 -[UIApplication sendAction:to:from:forEvent:] + 75
    6   UIKit                               0x000000010880f50a -[UIControl _sendActionsForEvents:withEvent:] + 467
    7   UIKit                               0x0000000108e26d39 -[UITextField _resignFirstResponder] + 256
    8   UIKit                               0x0000000108e26bab -[UITextField _finishResignFirstResponder] + 45
    9   UIKit                               0x000000010888078b -[UIResponder resignFirstResponder] + 114
    10  UIKit                               0x0000000108e26b04 -[UITextField resignFirstResponder] + 114
    11  UIKit                               0x0000000108880575 -[UIResponder becomeFirstResponder] + 284
    12  UIKit                               0x000000010876fb81 -[UIView(Hierarchy) becomeFirstResponder] + 99
    13  UIKit                               0x0000000108e26307 -[UITextField becomeFirstResponder] + 51
    14  UIKit                               0x0000000108ab5d4e -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 177
    15  UIKit                               0x0000000108ab7dc0 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 2263
    16  UIKit                               0x0000000108aad656 _UIGestureRecognizerSendActions + 262
    17  UIKit                               0x0000000108aac2f9 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 532
    18  UIKit                               0x0000000108ab0f16 ___UIGestureRecognizerUpdate_block_invoke662 + 51
    19  UIKit                               0x0000000108ab0e12 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 254
    20  UIKit                               0x0000000108aa6e8d _UIGestureRecognizerUpdate + 2796
    21  UIKit                               0x000000010874a646 -[UIWindow _sendGesturesForEvent:] + 1041
    22  UIKit                               0x000000010874b272 -[UIWindow sendEvent:] + 666
    23  UIKit                               0x0000000108711541 -[UIApplication sendEvent:] + 246
    24  UIKit                               0x000000010871ecdc _UIApplicationHandleEventFromQueueEvent + 18265
    25  UIKit                               0x00000001086f959c _UIApplicationHandleEventQueue + 2066
    26  CoreFoundation                      0x0000000107d91431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    27  CoreFoundation                      0x0000000107d872fd __CFRunLoopDoSources0 + 269
    28  CoreFoundation                      0x0000000107d86934 __CFRunLoopRun + 868
    29  CoreFoundation                      0x0000000107d86366 CFRunLoopRunSpecific + 470
    30  GraphicsServices                    0x000000010be31a3e GSEventRunModal + 161
    31  UIKit                               0x00000001086fc8c0 UIApplicationMain + 1282
    32  Clifford Bradford                   0x0000000107c33bb7 main + 135
    33  libdyld.dylib                       0x000000010a0fe145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException`.

It just points me to the first line of the AppDelegate.swift which doesn't really help me. Here is the corresponding code that adds the textField to the view. I would like to add that the contView is inside a scrollView.

        var otherVehiclePlateNum:UITextField = UITextField(frame: CGRectMake(carLabel.bounds.origin.x + 15, carLabel.frame.maxY + 10, self.contView.frame.width - 30, 25))
        otherVehiclePlateNum.placeholder = "TEST"
        self.contView.addSubview(otherVehiclePlateNum)


非常感谢您的帮助,我对此一无所知。

最佳答案

看第一行:numOfOtherVehiclesUpdated:方法实际上是否存在于OtherVehiclesViewController类中?确保在调用任何@selector时使冒号与签名匹配(即,您可能具有numOfOtherVehiclesUpdated方法,该方法与带有参数的numOfOtherVehiclesUpdated:不同)。

先看看那里-您可能是无意中打来的

关于ios - UITextField触摸时崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31799844/

10-12 00:30
查看更多