Skip to content

Instantly share code, notes, and snippets.

@DougFischer
Last active January 4, 2016 18:49
Show Gist options
  • Save DougFischer/8663310 to your computer and use it in GitHub Desktop.
Save DougFischer/8663310 to your computer and use it in GitHub Desktop.
Programmatically open dropdown or combobox on UIWebView
//
// AppDelegate.m
// DOMTest
//
// Created by Douglas Fischer on 1/28/14.
// Copyright (c) 2014 Abacomm Brasil. All rights reserved.
//
#import "AppDelegate.h"
#import "TestViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
TestViewController *testViewController = [[TestViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:testViewController];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
@end
@interface TestViewController : UIViewController
@end
#import "TestViewController.h"
@interface TestViewController ()
@property (nonatomic, strong) UIWebView *webView;
- (void)initUIElements;
- (void)leftBarButtonTapped;
@end
@implementation TestViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initUIElements];
}
- (void)initUIElements {
_webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_webView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_webView.keyboardDisplayRequiresUserAction = NO;
[self.view addSubview:_webView];
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Simulate" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonTapped)];
self.navigationItem.leftBarButtonItem = leftBarButton;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSURL *url = [NSURL URLWithString:@"https://docs.google.com/forms/d/1bQPAK6TpekQGXiY6NjtUMnJFXtVpzW74gFoJ25wgnuk/viewform"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
}
#pragma mark - Button Handling
- (void)leftBarButtonTapped {
NSString *result = [_webView stringByEvaluatingJavaScriptFromString:@"document.forms[0].elements[0].focus()"];
NSLog(@"[%@]", result);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment