我正在尝试将 JavaScript 加载到 UIWebView 中。下面是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
NSString *javascript = [[NSString alloc] initWithContentsOfFile:@"script.js" encoding:NSUTF8StringEncoding error:nil];
[webView stringByEvaluatingJavaScriptFromString:javascript];
}
我在这里做错了吗?Web 视图完成加载,所以我假设我在 Javascript 上做错了什么。