So what is happening in that scenario?
This error is caused if an INPUT element that contains text has the focus, and then the click of the button causes the input to lose focus, and then double-click on the input to regain focus and select Cut Copy and paste from the pop-up bar.
This means that when the HTML in the WebView page has the following code
<type= "text"><type= "button" >
When there are input boxes and buttons, [UIWebView Cut:]: Unrecognized selector sent to instance error risk
Simply put, if there is an input box in the WebView, and there is a button, do the following operation will appear such an error:
1. Enter the contents in the input box.
2. Click button to make the keyboard disappear.
3. Double-click the content in the input box to select Bar and tap clip. There will be a flash-back phenomenon.
The specific errors are as follows:
-- One- - One: -:59.495webviewcuterrordemo[3381:595295]-[uiwebview Cut:]: Unrecognized selector sent to instance0x7f9612f19f40 -- One- - One: -:59.497webviewcuterrordemo[3381:595295] * * * * terminating app due to uncaught exception'nsinvalidargumentexception', Reason:'-[uiwebview Cut:]: Unrecognized selector sent to instance 0x7f9612f19f40'FirstThrowCall stack: (0Corefoundation0x000000010ddb6f45__exceptionpreprocess +165 1LIBOBJC. A.dylib0x000000010d82edebObjc_exception_throw + - 2Corefoundation0x000000010ddbf56d-[nsobject (NSObject) Doesnotrecognizeselector:] +205 3Corefoundation0x000000010dd0ceea___forwarding___ +970 4Corefoundation0x000000010dd0ca98_cf_forwarding_prep_0 + - 5UIKit0x000000010e6a3923-[uicalloutbar buttonpressed:] +414 6UIKit0x000000010e6a1e47-[uicalloutbarbutton Fadeandsendaction] +Bayi 7Foundation0x000000010d416c39__nsfiredelayedperform +402 8Corefoundation0x000000010dd17264__cfrunloop_is_calling_out_to_a_timer_callback_function__ + - 9Corefoundation0x000000010dd16e11__cfrunloopdotimer +1089 TenCorefoundation0x000000010dcd8821__cfrunlooprun +1937 OneCorefoundation0x000000010dcd7e08Cfrunlooprunspecific +488 AGraphicsservices0x000000011158fad2Gseventrunmodal +161 -UIKit0x000000010e16430dUiapplicationmain +171 -Webviewcuterrordemo0x000000010d32c86fMain +111 theLibdyld.dylib0x00000001104f292dStart +1) libc++abi.dylib:terminating with uncaught exception of type NSException
Take a closer look at the third-party login page There is a risk of this problem.
Some people say that this is a bug in the Apple system because the operation is not sent correctly in the response chain and is eventually sent to the UIWebView instance, not the internal uiwebdocumentview.
Here's a solution to this problem, and the idea is to dynamically add a response to the UIWebView.
Create a new class Cutcopypastefixedwebview inherit UIWebView
The CutCopyPasteFixedWebView.h code is as follows
// // CutCopyPasteFixedWebView.h// webviewcuterrordemo / /// Created by Lidaojian on 15/11/20. // copyright©2015 year Lidaojian. All rights reserved. // #import <UIKit/UIKit.h>@interface cutcopypastefixedwebview:uiwebview @end
The CUTCOPYPASTEFIXEDWEBVIEW.M code is as follows
////cutcopypastefixedwebview.m//Webviewcuterrordemo////Created by Lidaojian on 15/11/20.//copyright©2015 year Lidaojian. All rights reserved.//#import "CutCopyPasteFixedWebView.h"#import<objc/runtime.h>@implementationCutcopypastefixedwebview-(Instancetype) initWithFrame: (cgrect) frame{ Self=[Super Initwithframe:frame]; if(self) {///adaptation to prevent crashes[self preparefornocrashes]; } returnSelf ;}-(UIView *) internalview{Static Const CharInternalviewkey =' /'; ///Dynamic CorrelationUIView *internalview = Objc_getassociatedobject (self, &Internalviewkey); if(Internalview = = Nil && self.subviews.count >0) { for(UIView *viewinchself.scrollView.subviews) {if([[View].classDescription] Hasprefix:@"Uiweb"]) {Internalview=view; Objc_setassociatedobject (Self,&Internalview, view, objc_association_assign); Break; } } } returnInternalview;}voidWebviewimplementuiresponderstandardeditactions (IDSelf, SEL selector,IDparam) { ///IMP is essentially a function pointer methodforselector obtains a pointer to a method implementation, and can use the pointer to directly invoke the method implementationIMP imp =[[Self internalview] methodforselector:selector]; ///function Pointers void(*method) (ID, SEL,ID) = (void(*) (ID, SEL,ID) ) Imp; ///invoking a method directly with a function pointermethod ([self internalview], selector, param); }- (void) preparefornocrashes{Nsarray*selectors = @[@"Cut:",@"Copy:",@"Paste:",@"Select:",@"SelectAll:",@"Delete:",@"Maketextwritingdirectionlefttoright:",@"Maketextwritingdirectionrighttoleft:",@"Toggleboldface:",@"Toggleitalics:",@"Toggleunderline:",@"increasesize:",@"decreasesize:"]; for(NSString *selnameinchselectors) { ///dynamically get methods based on method namesSEL selector =nsselectorfromstring (selname); ///If the parent class is not implemented, add the Selector method to the parent class, and if the parent class implements it, the Selector method of the parent class is not modifiedClass_addmethod (self.class, selector, (IMP) webviewimplementuiresponderstandardeditactions,""); }}@end
Additional HTML files attached to the test
<HTML> <Head> </Head> <Body> <BR><BR> <inputtype= "text"> <inputtype= "button" > </body>
If you have any questions, please add my qq:610774281. Together to explore progress together ....
Reference connection:
http://stackoverflow.com/questions/21316784/uiwebview-bug-uiwebview-cut-unrecognized-selector-sent-to-instance#
IOS error [UIWebView cut:]: Unrecognized selector sent to instance