0

My app keeps crashing whenever I tap on a UITextField that I add to my view programmatically. Here is the stack trace if it is of any help:

'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)

Thanks so much for your help, I've been stuck on this.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
nickfhs
  • 13
  • 5
  • 1
    Did you setup some event handler to use a method named `numOfOtherVehiclesUpdated:`? You either didn't actually implement the method (with the proper number of arguments) or you put it on the wrong class. – rmaddy Aug 04 '15 at 02:52
  • Yeah this was correct, it was hooked up to my ViewController from my Storyboard from testing a while ago. Anyways, just deleted it in storyboard and its all good. Thanks! – nickfhs Aug 04 '15 at 03:08
  • possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](http://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Hot Licks Aug 04 '15 at 03:10

1 Answers1

0

Look at the first line: Does the method numOfOtherVehiclesUpdated: actually exist in the OtherVehiclesViewController class? Make sure that that if you're calling any @selectors that the colon matches the signature (i.e., you may have a numOfOtherVehiclesUpdated method, which isn't the same as numOfOtherVehiclesUpdated: which takes a parameter).

Look there first - you may be calling that by accident

Cameron
  • 1,142
  • 8
  • 32
  • Oh my gosh I can't believe I overlooked that. That was it. I used it when I was testing something earlier. For whatever reason it was hooked up to something in my ViewController in Storyboard and all it took was deleting it in the connections inspector. This is my first time making an app so it's coming along slowly. Anyways, thank you Cameron – nickfhs Aug 04 '15 at 03:07
  • Glad it was that simple... it happens to all of us from time to time. :) – Cameron Aug 04 '15 at 03:19