应用程序在textview.becomeFirstResponder上崩溃 [英] App crashed at textview.becomeFirstResponder

查看:738
本文介绍了应用程序在textview.becomeFirstResponder上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用有时会在调用textView.becomeFirstResponder()时崩溃.抛出的错误很奇怪:

My app sometimes crashes at the call to textView.becomeFirstResponder(). The error thrown is strange:

-[UITextSelectionView keyboardShownWithNotif:]: unrecognized selector sent to instance 0x16899070

有时候是:

-[UIImageView keyboardShownWithNotif:]: unrecognized selector sent to instance 0x178e2610

我确实添加了通知侦听器:

I did add notification listeners:

NotificationCenter.default.addObserver(self, selector: #selector(keyboardShown(notif:)), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardHidden), name: .UIKeyboardWillHide, object: nil)

但是观察者是我定义的自定义视图,为什么系统会向UITextSelectionViewUIImageView发送通知?

But the observer is the custom view I defined, why does the system send notification to UITextSelectionView or UIImageView?

在iOS 8.4.1中找到,在iOS 9中未复制.

Found in iOS 8.4.1, not reproduced in iOS 9.

这是怎么回事?

推荐答案

seems like you added an notif. observer to show/hide keyboard. 
Try to remove observer in dealloc method

 - (void) dealloc {
       [[NSNotificationCenter defaultCenter] removeObserver:self]; //Or whichever observer you want to remove
}

这篇关于应用程序在textview.becomeFirstResponder上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆