所以我有一个基于 webview 的应用程序。我对键盘进行了一些修改(不是问题,将它们全部删除以进行故障排除)。
在 iPhone 6+ 模拟器上,当处于横向模式时,如果复制了某些内容,并且您使用键盘粘贴按钮(不是上下文按钮),应用程序会崩溃。我在尝试使用键盘剪切按钮时也注意到了这一点。
下面崩溃如下:
-[UIThreadSafeNode _responderForEditing]: unrecognized selector sent to instance 0x7ff4364344c0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIThreadSafeNode _responderForEditing]: unrecognized selector sent to instance 0x7ff4364344c0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010df98f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010da12deb objc_exception_throw + 48
2 CoreFoundation 0x000000010dfa156d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010deeeeea ___forwarding___ + 970
4 CoreFoundation 0x000000010deeea98 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010c31eb4a -[UIKeyboardLayoutStar touchDownWithKey:atPoint:executionContext:] + 1445
6 UIKit 0x000000010c878ef0 -[UIKeyboardTaskExecutionContext returnExecutionToParentWithInfo:] + 278
7 UIKit 0x000000010c3169de -[UIKeyboardLayoutStar performHitTestForTouchInfo:touchStage:executionContextPassingUIKBTree:] + 1525
8 UIKit 0x000000010c31de57 -[UIKeyboardLayoutStar touchDown:executionContext:] + 533
9 UIKit 0x000000011df96fb5 -[UIKeyboardLayoutStarAccessibility touchDown:executionContext:] + 61
10 UIKit 0x000000010c8793ab -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 332
11 UIKit 0x000000010c1347bd -[UIKeyboardLayout touchDown:] + 159
12 UIKit 0x000000010c1352ef -[UIKeyboardLayout touchesBegan:withEvent:] + 415
13 UIKit 0x000000010bee2cc2 -[UIWindow _sendTouchesForEvent:] + 308
14 UIKit 0x000000010bee3c06 -[UIWindow sendEvent:] + 865
15 UIKit 0x000000010be932fa -[UIApplication sendEvent:] + 263
16 UIKit 0x000000011df66a29 -[UIApplicationAccessibility sendEvent:] + 77
17 UIKit 0x000000010be6dabf _UIApplicationHandleEventQueue + 6844
18 CoreFoundation 0x000000010dec5011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x000000010debaf3c __CFRunLoopDoSources0 + 556
20 CoreFoundation 0x000000010deba3f3 __CFRunLoopRun + 867
21 CoreFoundation 0x000000010deb9e08 CFRunLoopRunSpecific + 488
22 GraphicsServices 0x000000010ead2ad2 GSEventRunModal + 161
23 UIKit 0x000000010be7330d UIApplicationMain + 171
很明显,因为我使用的是 webview,所以没有实际的 textview 可以绑定(bind)到它。
我该如何解决?我不关心通过应用商店审核,所以欢迎使用私有(private) API 或其他非苹果认可的方法。
如有任何帮助,我们将不胜感激。谢谢。
最佳答案
这是 Apple 的 bug,因为这个选择器应该传递给 UIResponder,但是 UIThreadSafeNode 是 NSObject 的子类。为了解决这个问题,您可以实现 NSObject 类别:
@interface UIView (FirstResponder)
-(id)findFirstResponder;
@end
@implementation UIView (FirstResponder)
- (id)findFirstResponder
{
if (self.isFirstResponder) {
return self;
}
for (UIView *subView in self.subviews) {
id responder = [subView findFirstResponder];
if (responder) return responder;
}
return nil;
}
@end
@interface NSObject (KeyboardBUI)
-(_Nonnull id)_responderForEditing;
@end
@implementation NSObject (KeyboardBUI)
-(_Nonnull id)_responderForEditing
{
return self;
}
-(void)cut:(nullable id)sender
{
NSString *selection = [[self getWebView] stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
[[self getWebView] stringByEvaluatingJavaScriptFromString:@"document.execCommand('delete', false, null)"];
[UIPasteboard generalPasteboard].string = selection;
}
-(void)paste:(nullable id)sender
{
NSString *text = [UIPasteboard generalPasteboard].string;
[[self getWebView] stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.execCommand('insertHTML', false, '%@')", text]];
}
-(void)copy:(nullable id)sender
{
NSString *selection = [[self getWebView] stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
[UIPasteboard generalPasteboard].string = selection;
}
-(void)toggleItalics:(nullable id)sender
{
[[self getWebView] stringByEvaluatingJavaScriptFromString:@"document.execCommand(\"Italic\")"];
}
-(void)toggleUnderline:(nullable id)sender
{
[[self getWebView] stringByEvaluatingJavaScriptFromString:@"document.execCommand(\"Underline\")"];
}
-(void)toggleBoldface:(nullable id)sender
{
[[self getWebView] stringByEvaluatingJavaScriptFromString:@"document.execCommand(\"Bold\")"];
}
-(UIWebView * __nullable)getWebView
{
UIWebView *retVal = nil;
id obj = [[[[[UIApplication sharedApplication] keyWindow] findFirstResponder] superview] superview];
if ([obj isKindOfClass:[UIWebView class]]) {
retVal = obj;
}
return retVal;
}
@end
注意:我不知道这是否会通过 Apple Appstore 审核。
UIView (FirstResponder) 来自这个 answer 的类别.
复制/粘贴/剪切此 answer
关于ios - UIWebview [UIThreadSafeNode _responderForEditing] 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33807812/
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上
代码:threads=[]Thread.abort_on_exception=truebegin#throwexceptionsinthreadssowecanseethemthreadseputs"EXCEPTION:#{e.inspect}"puts"MESSAGE:#{e.message}"end崩溃:.rvm/gems/ruby-2.1.3@req/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:478:inload_missing_constant':自动加载常量MyClass时检测到循环依赖稍加研究后,
当我将IO::popen与不存在的命令一起使用时,我在屏幕上打印了一条错误消息:irb>IO.popen"fakefake"#=>#irb>(irb):1:commandnotfound:fakefake有什么方法可以捕获此错误,以便我可以在脚本中进行检查? 最佳答案 是:升级到ruby1.9。如果您在1.9中运行它,则会引发Errno::ENOENT,您将能够拯救它。(编辑)这是在1.8中的一种hackish方式:error=IO.pipe$stderr.reopenerror[1]pipe=IO.popen'qwe'#
当我尝试使用“套接字”库中的方法“read_nonblock”时出现以下错误IO::EAGAINWaitReadable:Resourcetemporarilyunavailable-readwouldblock但是当我通过终端上的IRB尝试时它工作正常如何让它读取缓冲区? 最佳答案 IgetthefollowingerrorwhenItrytousethemethod"read_nonblock"fromthe"socket"library当缓冲区中的数据未准备好时,这是预期的行为。由于异常IO::EAGAINWaitReadab
任何人都可以解释为什么当对方法的调用看起来像这样时我可能会看到这个堆栈(由HTTParty::post请求引起):beginresponse=HTTParty::post(url,options)rescuelogger.warn("Couldnotpostto#{url}")rescueTimeout::Errorlogger.warn("Couldnotpostto#{url}:timeout")end堆栈:/usr/local/lib/ruby/1.8/timeout.rb:64:in`timeout'/usr/local/lib/ruby/1.8/net/protocol.rb