【问题标题】:Not able to select dropdown in UIWebView for IOS 9无法在 iOS 9 的 UIWebView 中选择下拉菜单
【发布时间】:2016-09-01 13:31:07
【问题描述】:
我在 UIWebView 中显示一个网站页面,该页面有一个下拉菜单。用户可以从下拉列表中选择值,但是当应用程序关闭并再次打开时,此下拉列表停止工作意味着用户无法选择它。
奇怪的是,如果我们在该 dropdwon 上显示 javascript onclick 的警报框,那么在点击警报框的 ok 按钮后一切正常(意味着 dropdwon 变得可点击),那么它的原因和解决方案是什么?
【问题讨论】:
标签:
html
ios
objective-c
uiwebview
xib
【解决方案1】:
我遇到了同样的问题,所以我找到了解决方法
在您的网站中,将以下 javascript 行放入 document.ready 中,其中存在下拉菜单
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 行时 上面的代码不会显示任何视图控制器,但它会触发下拉菜单再次工作