那在什么场景中会出现这种情况呢?

如果一个包含文字的输入元素有焦点,然后按钮的点击会导致输入失去焦点,然后接下来在输入时双按会重新得到焦点并从弹出bar中选择剪切复制粘贴,就会导致此error。

也就是说当WebView页面中的HTML中有如下代码的时候

<input type="text">
<input type="button" >

即有输入框和按钮的时候,会出现 [UIWebView cut:]: unrecognized selector sent to instance 的错误风险

简单的说就是若有一个WebView中有输入框,又有按钮的话,执行下面的操作就会出现这样的错误:

1.在输入框中输入内容。

2.点击Button让键盘消失。

3。双击输入框中的内容出现选择的bar后点击剪贴。就会出现闪退的现象。

的具体错误如下:

-- ::59.495 WebViewCutErrorDemo[:] -[UIWebView cut:]: unrecognized selector sent to instance 0x7f9612f19f40
-- ::59.497 WebViewCutErrorDemo[:] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIWebView cut:]: unrecognized selector sent to instance 0x7f9612f19f40'
*** First throw call stack:
(
CoreFoundation 0x000000010ddb6f45 __exceptionPreprocess +
libobjc.A.dylib 0x000000010d82edeb objc_exception_throw +
CoreFoundation 0x000000010ddbf56d -[NSObject(NSObject) doesNotRecognizeSelector:] +
CoreFoundation 0x000000010dd0ceea ___forwarding___ +
CoreFoundation 0x000000010dd0ca98 _CF_forwarding_prep_0 +
UIKit 0x000000010e6a3923 -[UICalloutBar buttonPressed:] +
UIKit 0x000000010e6a1e47 -[UICalloutBarButton fadeAndSendAction] +
Foundation 0x000000010d416c39 __NSFireDelayedPerform +
CoreFoundation 0x000000010dd17264 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ +
CoreFoundation 0x000000010dd16e11 __CFRunLoopDoTimer +
CoreFoundation 0x000000010dcd8821 __CFRunLoopRun +
CoreFoundation 0x000000010dcd7e08 CFRunLoopRunSpecific +
GraphicsServices 0x000000011158fad2 GSEventRunModal +
UIKit 0x000000010e16430d UIApplicationMain +
WebViewCutErrorDemo 0x000000010d32c86f main +
libdyld.dylib 0x00000001104f292d start +
)
libc++abi.dylib: terminating with uncaught exception of type NSException

仔细想想第三方登录的页面有出现这种问题的风险。

有人说这里面说是苹果系统的bug,原因是这种操作在响应链不能正确的发送,并最终发送到UIWebView的实例,而不是内部的UIWebDocumentView。

下面提供一下这种问题的解决方案,思想就是动态的为UIWebView添加响应的方法。

新建一个类 CutCopyPasteFixedWebView 继承 UIWebView

CutCopyPasteFixedWebView.h代码如下

//
// CutCopyPasteFixedWebView.h
// WebViewCutErrorDemo
//
// Created by lidaojian on 15/11/20.
// Copyright © 2015年 lidaojian. All rights reserved.
// #import <UIKit/UIKit.h> @interface CutCopyPasteFixedWebView : UIWebView @end

CutCopyPasteFixedWebView.m代码如下

//
// CutCopyPasteFixedWebView.m
// WebViewCutErrorDemo
//
// Created by lidaojian on 15/11/20.
// Copyright © 2015年 lidaojian. All rights reserved.
// #import "CutCopyPasteFixedWebView.h"
#import <objc/runtime.h> @implementation CutCopyPasteFixedWebView - (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
/// 适配防止崩溃
[self prepareForNoCrashes];
}
return self;
} - (UIView *)internalView
{
static const char internalViewKey = '\0';
/// 动态关联
UIView *internalView = objc_getAssociatedObject(self, &internalViewKey);
if (internalView == nil && self.subviews.count > ) {
for (UIView *view in self.scrollView.subviews) {
if ([[view.class description] hasPrefix:@"UIWeb"]) {
internalView = view;
objc_setAssociatedObject(self, &internalView, view, OBJC_ASSOCIATION_ASSIGN);
break;
}
}
}
return internalView;
} void webViewImplementUIResponderStandardEditActions(id self, SEL selector, id param)
{
/// IMP本质就是函数指针 methodForSelector 获得一个指向方法实现的指针,并可以使用该指针直接调用方法实现
IMP imp = [[self internalView] methodForSelector:selector]; /// 函数指针
void (*method)(id, SEL, id) = (void (*) (id, SEL, id))imp; /// 直接用函数指针调用方法
method([self internalView], selector, param); } - (void)prepareForNoCrashes
{
NSArray *selectors = @[@"cut:", @"copy:", @"paste:", @"select:", @"selectAll:", @"delete:", @"makeTextWritingDirectionLeftToRight:", @"makeTextWritingDirectionRightToLeft:", @"toggleBoldface:", @"toggleItalics:", @"toggleUnderline:", @"increaseSize:", @"decreaseSize:"]; for (NSString *selName in selectors) { /// 动态的根据方法名来获取方法
SEL selector = NSSelectorFromString(selName); /// 若父类没有实现则给父类添加selector方法,若父类实现了,并不修改父类的selector方法
class_addMethod(self.class, selector, (IMP)webViewImplementUIResponderStandardEditActions, "");
}
} @end

另外附上测试的HTML文件

<html>
<head>
</head>
<body>
<br><br>
<input type="text">
<input type="button" >
</body
</html>

若有疑问请加本人QQ:610774281。一起探讨一起进步。。。。

参考连接:

http://stackoverflow.com/questions/21316784/uiwebview-bug-uiwebview-cut-unrecognized-selector-sent-to-instance#

IOS 错误 [UIWebView cut:]: unrecognized selector sent to instance的更多相关文章

  1. iOS:编译错误[__NSDictionaryM objectAtIndexedSubscript:]: unrecognized selector sent to instance 0xa79e61

    这个意思是,__NSDictionaryM  无法将值传到下标索引对象,言简意赅就是数组越界.可是再看看,这是数组吗?不是,所以.遇到这样的crash,我这里有两种情况: 1.首先看看你 indexP ...

  2. -[__NSArrayI removeAllObjects]: unrecognized selector sent to instance 0x7fa8dc830110

    问题 今天做项目,遇到了这个问题 -[__NSArrayI removeAllObjects]: unrecognized selector sent to instance 0x7fa8dc8301 ...

  3. [NSConcreteValue doubleValue]: unrecognized selector sent to instance

    今天需求说要给在进入某个页面给某个按钮加上放大效果,心想这还不简单,于是三下五除二的把动画加上提交测试了. 下面是动画的代码 NSTimeInterval time = CACurrentMediaT ...

  4. iOS 程序报错:reason: [NSArrayI addObject:]: unrecognized selector sent to instance

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI ad ...

  5. CBUUID UUIDString unrecognized selector sent to instance 错误

    CBUUID UUIDString unrecognized selector sent to instance 错误 ios7.0,4s 蓝牙出现上述错误! 查看api可知,错误原因,由于CBUUI ...

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

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

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

    开发IOS整合微信API的时候,在运行程序的过程中可能会在注册你的APPID的时候抛出此异常而导致程序崩溃. 异常描述 [7661:2826851] *** Terminating app due t ...

  8. iOS开发——异常:[__NSCFNumber length]: unrecognized selector sent to instance

      *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumbe ...

  9. Solve Error: 'NSInvalidArgumentException', reason: '-[UITableView mas_makeConstraints:]: unrecognized selector sent to instance 0x7fa5c402fa00'

    下面是iOS开发用第三方库可能出现的错误,及其解决方法: 1. 'NSInvalidArgumentException', reason: '-[UITableView mas_makeConstra ...

随机推荐

  1. 30 天精通 Git 版本控管

    https://github.com/doggy8088/Learn-Git-in-30-days

  2. NoSQL生态系统——类似Bigtable列存储,或者Dynamo的key存储(kv存储如BDB,结构化存储如redis,文档存储如mongoDB)

    摘自:http://www.ituring.com.cn/article/4002# NoSQL系统的数据操作接口应该是非SQL类型的.但在NoSQL社区,NoSQL被赋予了更具有包容性的含义,其意为 ...

  3. MySQL 性能优化 30个数据库设计的最佳实践

    数据库设计是整个程序的重点之一,为了支持相关程序运行,最佳的数据库设计往往不可能一蹴而就,只能反复探寻并逐步求精,这是一个复杂的过程,也是规划和结构化数据库中的数据对象以及这些数据对象之间关系的过程. ...

  4. ubuntu - 中文

    首先要从Ubuntu语言设置那里,把中文语言包安装上 打开/etc/environment 在下面添加如下两行 LANG="zh_CN.UTF-8″ LANGUAGE="zh_CN ...

  5. Spring Quartz

    Spring  Quartz Quartz是一个强大的企业级任务调度框架,Spring中继承并简化了Quartz,下面就看看在Spring中怎样配置Quartz: 首先我们来写一个被调度的类: pac ...

  6. Mysql触发器示例

    begin ); ); ); then set x = (select ID from qn_huiyuan_grade g ); elseif r then set x = (select ID f ...

  7. js判断是否是移动端 访问移动端网址

    1以下为代码,可放置在网站foot底部文件,或者haead顶部文件,建议将代码放在网站顶部,这样可以实现手机访问立即跳转! <script src="http://siteapp.ba ...

  8. Python 面向对象[Day 06]

     面向对象编程(Object-Oriented Programming)  概述 面向过程:根据业务逻辑从上至下写代码,实现所需功能. 函数式:将某些功能代码封装至函数中,在需要时调用函数,函数式代码 ...

  9. (1)WCF少废话系列之 _Hello WCF!

    本节旨在通过实例的方式让初学者对WCF有一个感性的认识,坚持由特殊到普遍再由普遍到特殊的认知规律. WCF(Windows Communication Fundation),微软分布式通信架构的集合, ...

  10. .netcore跨平台 之 windows上编译,ubuntu上运行

    1 下载并安装netcore sdk    下载地址 https://github.com/dotnet/cli 选取合适的版本下载安装即可 打开 CMD ,输入dotnet,出现以下信息说明已安装好 ...