错误

app 在线上有个崩溃的问题, crash原因为-[UIKBBlurredKeyView candidateList]: unrecognized selector sent to instance.

原因分析

然后发现是在手写输入的时候会crash,每当提示文字的区域就会crash。这个崩溃是由在UIScrollview的category中重写的三个方法引起的, 代码如下:

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {[super touchesBegan:touches withEvent:event];[self.nextResponder touchesBegan:touches withEvent:event];
}- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {[super touchesMoved:touches withEvent:event];[self.nextResponder touchesMoved:touches withEvent:event];
}- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {[super touchesEnded:touches withEvent:event];[self.nextResponder touchesEnded:touches withEvent:event];
}- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {[super touchesCancelled:touches withEvent:event];[self.nextResponder touchesCancelled:touches withEvent:event];
}

具体原因是由于提示文字区域(Candidate View)点击时, 同样执行上面的代码, 然后事件响应向上传递, 直到出现标题的错误。
再具体些, 就是手写的键盘的提示文字的区域是UIKBCandidateCollectionView类(其父类是UIColloectionView)的实例,这个view的nextResponder是UIKBHandwritingCandidateView类的实例。执行UIKBHandwritingCandidateView的touchesBegan:withEvent:方法后,会使得整个candidate view呈选中状态,而苹果对于手写键盘的提示文字区域, 会避免candidate view呈选中状态的。整个candidate view呈选中状态后再点击键盘的任意地方,本应调用UIKBCandidateView实例的方法candidateList,结果调用了UIKBBlurredKeyView的candidateList方法,导致方法找不到,导致”-[UIKBBlurredKeyView candidateList]: unrecognized selector sent to instance “crash。

解决方案

方案一

摒弃此代码, 选择其他方式代替。

方案二

对于不同的类, 对其进行类型判断, 加强代码的健壮性, 以避免崩溃。比如, UIScrollView中要加入下判断:

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {if([self isMemberOfClass:[UIScrollView class]]) {[super touchesBegan:touches withEvent:event];[self.nextResponder touchesBegan:touches withEvent:event];}
}

方案三

使用UITapGestureRecognizer类, 进行用户的点击事件拦截, 且要将tap的cancelsTouchesInView属性设置为NO, 否则会屏蔽到当前View的点击事件。下面以UIScrollView和’UITableView’为例的处理方案:

1.在UIScrollView上面加一个UIView, 通过在view上面的手势来改变键盘

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];
tap.cancelsTouchesInView = NO;
[backView addGestureRecognizer:tap];

2.在UITableView上改变键盘

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];
tap.cancelsTouchesInView = NO;
[tableView addGestureRecognizer:tap];

错误:-[UIKBBlurredKeyView candidateList]: unrecognized selector sent to instance相关推荐

  1. 静态库调用中“unrecognized selector sent to instance”错误

    在开发调用静态库的中,出现 "unrecognized selector sent to instance 0x2b5f90"的错误 -[__NSCFConstantString ...

  2. ios unrecognized selector sent to instance出现的原因和解决方案

    概述:造成unrecognized selector sent to instance iphone,大部分情况下是因为对象被提前release了,在你心里不希望他release的情况下,指针还在,对 ...

  3. 小萝莉说Crash(一):Unrecognized selector sent to instance xxxx

    写在前面的:分享一篇文,原文地址:小萝莉说Crash(一):Unrecognized selector sent to instance xxxx -------------------------- ...

  4. 【小萝莉说Crash】第一期:Unrecognized selector sent to instance xxxx

    大家好,我是来自Bugly Crash实验室的小萝莉(害羞ing),很高兴能和大家一起讨论关于移动终端App的Crash问题及解决方法. 在上次的"精神哥讲Crash"系列中,精神 ...

  5. 问题--[__NSCFNumber length]: unrecognized selector sent to instance 0x8b3c310’ - andy_shen

    程序运行出现这个错误 : 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector se ...

  6. IOS微信API异常:unrecognized selector sent to instance 0x17005c9b0'

    2019独角兽企业重金招聘Python工程师标准>>> 开发IOS整合微信API的时候,在运行程序的过程中可能会在注册你的APPID的时候抛出此异常而导致程序崩溃. 异常描述 [76 ...

  7. 【iOS】使用storyboard界面跳转报错:unrecognized selector sent to instance 0x7

    使用storyboard直接model界面跳转的时候出现报错:unrecognized selector sent to instance 0x7... 网上查了相似的问题但是依旧没有找到解决方法,后 ...

  8. IOS微信API异常:unrecognized selector sent to instance 0x17005c9b0‘

    IOS微信API异常:unrecognized selector sent to instance 0x17005c9b0' 参考文章: (1)IOS微信API异常:unrecognized sele ...

  9. unrecognized selector sent to instance

    [iOS] Error Fixed : [__NSArrayI addObject:]: unrecognized selector sent to instance 当我创建了一个NSMutable ...

最新文章

  1. Ansible YML语法
  2. inet_ntop php,inet_ntop()
  3. P3708-koishi的数学题【差分】
  4. php 公众号验证回调方法_微信公众号关键词自动回复设置方法!
  5. 利用Python3发送邮件-亲测可行
  6. MySQL之 分库分表
  7. 电脑怎么开护眼模式_心累!整天对着手机电脑,到底该怎么护眼啊啊啊
  8. spring-第十三篇之零配置支持
  9. 银河麒麟桌面操作系统sp1 2203双硬盘ghost备份及手动分区还原
  10. 整流五 - PWM整流器无差拍控制 一(重复控制算法)
  11. 八、软考·系统架构师——架构设计
  12. 网络安全-CTF取证方法大汇总,建议收藏!
  13. 阈值、阙值 有没有阀值?
  14. dataframe一列拆分成多列
  15. C#中二维数组的二维长度
  16. 磁盘检查清理修复命令
  17. 什么是反射?为什么使用反射?
  18. 如何 SolidWorks 减小文件大小?
  19. linux 网卡绑定team和删除team
  20. 597-Golang的类型声明、struct结构体

热门文章

  1. ScalaTest User Guide
  2. access实验报告体会_access实验报告电子版2013_图文
  3. Django小项目--理财产品信息管理系统
  4. 移动WEB开发四、rem布局
  5. Hadoop HA namenode宕机环境恢复
  6. layui 表格字体_Layui表格自定义表格字体样式
  7. 购物网站前景喜人 做大做强却颇费心思
  8. freetype简介与测试
  9. Cocos2dx Lua开发环境搭建
  10. 0xc000007b应用程序无法正常启动,dll损坏