html - 无法在 IOS 9 的 UIWebView 中选择下拉菜单

标签 html ios objective-c uiwebview xib

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

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

最佳答案

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

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

在你有 UIWebView 的 Controller 中放置以下代码

  - (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 行时,上面的代码不会显示任何 View Controller ,但会触发下拉列表再次工作

关于html - 无法在 IOS 9 的 UIWebView 中选择下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39272945/

相关文章:

html - 修复没有最小高度的溢出

javascript - 使用 javascript 添加/删除输入字段

ios - 如何将 UISearchBar 锁定到位以监督

ios - 是否可以响应 UIAlertView 中的摇动手势?

php - 创建登录表单

javascript - 将文本字段中的文本添加到 JavaScript 中的选择框中?

ios - 在 Swift 中,您如何检测哪些 UIControlEvents 触发了操作?

ios - 如何在 if 语句中使用可选值?

ios - 对于非英语歌曲,如何使用 # 显示看起来像 iPod 音乐的索引

ios - 在 Objective-C 中取消分配对象的属性