【发布时间】:2020-08-15 23:50:28
【问题描述】:
我正在使用 xCode 开发一个应用程序,并且我有一个 numberPad / decimalPad,当在任何地方点击屏幕时我需要关闭它。是整个屏幕上的单个文本输入。我在网上看到,我在 viewDidLoad 上得到了以下代码:
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
view.addGestureRecognizer(tap)
接下来我在 viewDidLoad 之后添加了这个函数
@objc func dismissKeyboard() {
view.endEditing(true)
}
由于某种原因,我尝试了不同的方法,但在文本字段中插入值后点击屏幕时应用程序崩溃。
一直在网上到处寻找,但似乎没有任何东西可以解决这个问题。
我也会添加一个完成按钮和一个工具栏,但是 xCode 给了我错误,因为我还在学习还不能弄明白。
我正在运行最新版本的 xCode 并使用迄今为止可用的最新 Swift 版本进行编码。
有什么建议吗?
完整的崩溃日志:
2020-08-16 10:17:16.734232-0400 Melitus[10862:586552] 找不到支持 iPhone-PortraitTruffle-NumberPad 键盘类型 4 的键盘;使用 25764_PortraitTruffle_iPhone-Simple-Pad_Default 2020-08-16 10:17:16.767685-0400 Melitus[10862:586552] 找不到支持键盘 iPhone-PortraitTruffle-NumberPad 类型 4 的键盘;使用 25764_PortraitTruffle_iPhone-Simple-Pad_Default 2020-08-16 10:17:18.229188-0400 Melitus[10862:586552] -[Melitus.ViewController carbsLabel:]: 无法识别的选择器发送到实例 0x7fcc99f07b70 2020-08-16 44-27:44-24: 0400 Melitus [10862:586552] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[Melitus.ViewController carbsLabel:]:无法识别的选择器发送到实例 0x7fcc99f07b70”*** 第一次抛出调用堆栈:(0 CoreFoundation 0x00007fff23e3de6e __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff512539b2 objc_exception_throw + 48 2的CoreFoundation 0x00007fff23e5eb94 - [NSObject的(NSObject的)doesNotRecognizeSelector:] + 132 3 UIKitCore 0x00007fff49354af0 - [UIResponder doesNotRecognizeSelector:] + 302 4的CoreFoundation 0x00007fff23e4286c转发+ 1436 5的CoreFoundation 0x00007fff23e44b58 _CF_forwarding_prep_0 + 120 6 UIKitCore 0x00007fff49326c1d -[UIApplication sendAction:to:from:forEvent:] + 83 7 UIKitCore 0x00007fff48cd5baa -[UIContro升sendAction:至:forEvent:] + 223 8 UIKitCore 0x00007fff48cd5ef2 - [UIControl _sendActionsForEvents:withEvent:方法] + 396 9 UIKitCore 0x00007fff49632d69 - [的UITextField _resignFirstResponder] + 155 10 UIKitCore 0x00007fff49353dae - [UIResponder _finishResignFirstResponder] + 358 11 UIKitCore 0x00007fff496329af - [的UITextField _finishResignFirstResponder ] + 48 12 UIKitCore 0x00007fff49353f10 - [UIResponder resignFirstResponder] + 275 13 UIKitCore 0x00007fff49632829 - [的UITextField resignFirstResponder] + 93 14 UIKitCore 0x00007fff4964b0da - [UIView的(的UITextField)endEditing:] + 184 15 Melitus 0x000000010012311d $ sSo16UIViewControllerC7MelitusE15dismissKeyboardyyF + 205 16 Melitus 0x000000010012316b $ sSo16UIViewControllerC7MelitusE15dismissKeyboardyyFTo + 43 17 17 uikitcore 0x00007FFF48EB6358 - [UigestUreCognizertarget _SendActionWithEntarGognizer:] + 44 18 uikitcore 0x00007FFF48EC02BA _UIGESTURECOGNIZERERARGARTACTIONT + 109 19 UIKITCORE 0x00007FFF48EBCB89 _UIGESTURECOGNIZERANCTINGS + 295 20 U IKitCore 0x00007fff48ebbeda - [UIGestureRecognizer _updateGestureForActiveEvents] + 760 21 UIKitCore 0x00007fff48ead9cb _UIGestureEnvironmentUpdate + 2745 22 UIKitCore 0x00007fff48eaced4 - [UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 467 23 UIKitCore 0x00007fff48eacc5c - [UIGestureEnvironment _updateForEvent:窗口:] + 225 24 UIKitCore 0x00007fff49364277 - [的UIWindow的SendEvent :] + 4479 25 UIKitCore 0x00007fff4933e6d1 - [UIApplication的的SendEvent:] + 356 26 UIKitCore 0x00007fff493c94ce __dispatchPreprocessedEventFromEventQueue + 7628 27 UIKitCore 0x00007fff493cc692 __handleEventQueueInternal + 6584 28 UIKitCore 0x00007fff493c2f35 __handleHIDEventFetcherDrain + 88 29的CoreFoundation 0x00007fff23da1c91 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 30的CoreFoundation 0x00007fff23da1bbc __CFRunLoopDoSource0 + 76 31的CoreFoundation 0x00007fff23da1394 __CFRunLoopDoSources0 + 180 32 核心基础 0x00007fff23d9bf8e __CFRunLoopRun + 974 33 核心基础 0x00007ff f23d9b8a4 cfrunlooprunpecific + 404 34图形服务0x00007fff38c39bbe gseventrunmodal + 139 35 uikitcore 0x00007fff49325968 Uiapplicationmain + 1605 36 melitus 0x0000000100128a2b main + 75 37 libdyld.dylib 0x00007fff520ce1fd start + 1 38 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: 以 NSException 类型的未捕获异常终止
【问题讨论】:
-
你能发布崩溃日志吗?
-
线程 1:异常:“-[Melitus.ViewController carbsLabel:]:无法识别的选择器发送到实例 0x7f9953e0ae70”
-
这是 xCode 在点击键盘外的任意位置或按下工具栏上的“完成”按钮时出现的错误