无法 select UIWebView 中的下拉列表 IOS 9

Not able to select dropdown in UIWebView for IOS 9

我在 UIWebView 中显示一个网站页面,其中有一个下拉菜单。用户能够 select 下拉列表中的值,但是当应用程序关闭并再次打开时,此下拉列表停止工作意味着用户无法 select 它。

奇怪的是,如果我们在那个 dropdwon 上显示 javascript onclick 的警告框,那么在点击警告框的 ok 按钮后一切正常(意味着 dropdwon 变得可点击),那么可能是什么原因和解决方案吗?

我遇到了同样的问题,所以我找到了解决方法 在您的网站中,在 document.ready 中放置以下 javascript 行,其中存在下拉菜单

 var appname = 'yourappName';
        var actionName = 'displayAlert';
        var url = appname + '://' + actionName;
        document.location.href = url;

在你有 UIWebView 的控制器中放置以下代码

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

    // these need to match the values defined in your JavaScript
    NSString *myAppScheme = @"wfsapp";
    NSString *myActionType = @"displayAlert";

    // ignore legit webview requests so they load normally
    if (![request.URL.scheme isEqualToString:myAppScheme]) {
        return YES;
    }

    // get the action from the path
    NSString *actionType = request.URL.host;


    // look at the actionType and do whatever you want here
    if ([actionType isEqualToString:myActionType]) {
    /*    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Loading"
                                                        message:@"Initialising Search Filters..."
                                                       delegate:self
                                              cancelButtonTitle:NULL
                                              otherButtonTitles:nil];*/



        //[alert show];
    /*   UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@""
                                                                       message:NULL
                                                                preferredStyle:UIAlertControllerStyleActionSheet];
        alertController.view.hidden = YES;

        alertController.modalPresentationStyle  = UIModalPresentationCurrentContext;
        alertController.view.backgroundColor  = [UIColor clearColor];*/
        UIViewController *alertController = [UIViewController alloc];
        alertController.view.hidden  = YES;
        alertController.view.backgroundColor = [UIColor clearColor];

        self.view.backgroundColor = [UIColor clearColor];
        self.modalPresentationStyle = UIModalPresentationCurrentContext;

        [self presentViewController:alertController animated:NO completion:^ {




        }];
        [alertController dismissViewControllerAnimated:NO completion:nil];

    }

当您的页面加载并执行 javascript 行时 上面的代码不会显示任何内容 viewcontroller 但它会触发下拉菜单再次工作