今天发现一个很神奇的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;@endCIBSafeKeyboardTextField.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;
}@endhtml
<!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>

解决方案 »

  1.   

    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