很神奇的问题求大神

linlishu8 2018-04-20 04:59:19
今天发现一个很神奇的BUG,就是iPad10.3.3的系统下,当网页上有select控件的时候,添加自定义键盘,点击select就会崩溃,有啥办法解决?这里放上源码
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
webView.delegate = self;
[self.view addSubview:webView];

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
NSURL *url = [[NSURL alloc] initWithString:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];

[self.view addSubview:[CIBSafeKeyboardTextField sharedTextField]];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

NSString *absolutePath = request.URL.absoluteString;

NSString *scheme = @"rrcc://";

if ([absolutePath hasPrefix:scheme]) {
NSString *subPath = [absolutePath substringFromIndex:scheme.length];
NSString *methodName = [subPath stringByReplacingOccurrencesOfString:@"_" withString:@":"];
SEL sel = NSSelectorFromString(methodName);

if ([self respondsToSelector:sel]) {
[self performSelector:sel];
return NO;
}
}

return YES;
}

- (void)shareToTest {
[[CIBSafeKeyboardTextField sharedTextField] becomeFirstResponder];
}


CIBSafeKeyboardTextField.h

@interface CIBSafeKeyboardTextField : UITextField

+ (CIBSafeKeyboardTextField *)sharedTextField;

@end


CIBSafeKeyboardTextField.m

@implementation CIBSafeKeyboardTextField

+ (CIBSafeKeyboardTextField *)sharedTextField {
static CIBSafeKeyboardTextField *_textField = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_textField = [[self alloc] init];
});
return _textField;
}

- (instancetype)init
{
self = [super init];
if (self) {

self.inputView = [[UIView alloc] init];
}
return self;
}

@end


html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.btn{height:40px; width:60%; padding: 0px 30px; background-color: #0071E7; border: solid 1px #0071E7; border-radius:5px; font-size: 1.2em; color: white}
</style>
<script>
function myFunction() {
location.href = "rrcc://shareToTest";
}
</script>
</head>
<body>
<select name="hehe" id="">
<option value="1">hehe</option>
<option value="2">hehe</option>
<option value="3">hehe</option>
<option value="4">hehe</option>
<option value="5">hehe</option>
</select>
<button class="btn" type="button" onclick="myFunction()">键盘</button>

</body>
</html>
...全文
1207 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
linlishu8 2018-04-23
  • 打赏
  • 举报
回复
2018-04-23 09:39:36.802439+0800 inputView[764:145394] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (0) beyond bounds (0) for section (0).' *** First throw call stack: (0x1836b6fe0 0x182118538 0x1836b6f28 0x1899fa090 0x1899f98c8 0x189d63ef0 0x1897f9838 0x1897f95a8 0x189b32080 0x189a6e594 0x189a60630 0x1897d428c 0x1836649a8 0x183662630 0x183662a7c 0x183592da4 0x184ffd074 0x189846c9c 0x1000e0480 0x1825a159c) libc++abi.dylib: terminating with uncaught exception of type NSException
不担心 2018-04-22
  • 打赏
  • 举报
回复
要把错误信息贴出来

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧