1

This is the Swift code that I'm using to dismiss the keyboard whenever the user taps anywhere on the screen:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    self.view.endEditing(true)
}

When I tap on the text field, the keyboard appears, but when I then tap somewhere else, the console prints out the following:

libc++abi.dylib: terminating with uncaught exception of type NSException

What could be the problem?

The complete message:

2016-06-15 11:49:43.812 Converter[25968:425649] -[Converter.ViewController TextFieldAct:]: unrecognized selector sent to instance 0x7fa5dad437e0

2016-06-15 11:49:43.816 Converter[25968:425649] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Converter.ViewController TextFieldAct:]: unrecognized selector sent to instance 0x7fa5dad437e0'

*** First throw call stack:

(

0   CoreFoundation                      0x000000010e288d85 __exceptionPreprocess + 165

1   libobjc.A.dylib                     0x000000011002cdeb objc_exception_throw + 48

2   CoreFoundation                      0x000000010e291d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205

3   CoreFoundation                      0x000000010e1d7cfa ___forwarding___ + 970

4   CoreFoundation                      0x000000010e1d78a8 _CF_forwarding_prep_0 + 120

5   UIKit                               0x000000010eab2a8d -[UIApplication sendAction:to:from:forEvent:] + 92

6   UIKit                               0x000000010ec25e67 -[UIControl sendAction:to:forEvent:] + 67

7   UIKit                               0x000000010ec26143 -[UIControl _sendActionsForEvents:withEvent:] + 327

8   UIKit                               0x000000010f4af6c5 -[UITextField _resignFirstResponder] + 298

9   UIKit                               0x000000010ecc4a1a -[UIResponder _finishResignFirstResponder] + 292

10  UIKit                               0x000000010f4af4ef -[UITextField _finishResignFirstResponder] + 49

11  UIKit                               0x000000010ecc4b3b -[UIResponder resignFirstResponder] + 254

12  UIKit                               0x000000010f4af3bc -[UITextField resignFirstResponder] + 136

13  UIKit                               0x000000010f4c32a3 -[UIView(UITextField) endEditing:] + 199

14  Converter                           0x000000010e09d159 _TFC9Converter14ViewController12touchesBeganfTGVs3SetCSo7UITouch_9withEventGSqCSo7UIEvent__T_ + 169

15  Converter                           0x000000010e09d236 _TToFC9Converter14ViewController12touchesBeganfTGVs3SetCSo7UITouch_9withEventGSqCSo7UIEvent__T_ + 102

16  UIKit                               0x000000010ecc4227 forwardTouchMethod + 349

17  UIKit                               0x000000010ecc40b9 -[UIResponder touchesBegan:withEvent:] + 49

18  UIKit                               0x000000010eb25790 -[UIWindow _sendTouchesForEvent:] + 308

19  UIKit                               0x000000010eb266d4 -[UIWindow sendEvent:] + 865

20  UIKit                               0x000000010ead1dc6 -[UIApplication sendEvent:] + 263

21  UIKit                               0x000000010eaab553 _UIApplicationHandleEventQueue + 6660

22  CoreFoundation                      0x000000010e1ae301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17

23  CoreFoundation                      0x000000010e1a422c __CFRunLoopDoSources0 + 556

24  CoreFoundation                      0x000000010e1a36e3 __CFRunLoopRun + 867

25  CoreFoundation                      0x000000010e1a30f8 CFRunLoopRunSpecific + 488

26  GraphicsServices                    0x000000011291ead2 GSEventRunModal + 161

27  UIKit                               0x000000010eab0f09 UIApplicationMain + 171

28  Converter                           0x000000010e09ea92 main + 114

29  libdyld.dylib                       0x0000000110af092d start + 1

30  ???                                 0x0000000000000001 0x0 + 1

)

libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb) 
Larme
  • 24,190
  • 6
  • 51
  • 81
J164
  • 83
  • 8
  • I guess that the error message you post is not complete. Could you give the complete one? – Larme Jun 15 '16 at 08:48
  • `Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Converter.ViewController TextFieldAct:]:` That's the most important part of the error message. Do you call somewhere a method `TextFieldAct:` just after that? – Larme Jun 15 '16 at 08:53
  • I don't think so. There shouldn't be anything executing in the ViewController after the tap. – J164 Jun 15 '16 at 08:55
  • I think Larme is right, check the position where `TextFieldAct:` called, and who called it. – Klein Mioke Jun 15 '16 at 08:58
  • There are no mentions of `TextFieldAct` anywhere in the ViewController code. – J164 Jun 15 '16 at 09:00
  • 3
    That's why you get the exception. Because someone _sends_ a TextFieldAct: message to your view controller. Somewhere in your code, or in a storyboard. Of course that's hard to find. If there only was a FIND menu somewhere in Xcode... – gnasher729 Jun 15 '16 at 09:11
  • Yes, there is, that is how I know there are no mentions of it – J164 Jun 15 '16 at 09:13
  • Ok, I found the problem. It wasn't the ViewController, it was some outlet. – J164 Jun 15 '16 at 09:20

0 Answers0