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)