But when I run app, I can see how JS working. Where is my fault?
Also, I write NSLog(@"%@", self.webView) before and after self.webView.hidden = FALSE;
<UIWebView: 0x5e37720; frame = (0 44; 768 955); hidden = YES; autoresize = W+H; layer = <CALayer: 0x5e37780>>
<UIWebView: 0x5e37720; frame = (0 44; 768 955); autoresize = W+H; layer = <CALayer: 0x5e37780>>
FirstViewController.m :
- (void)webViewDidStartLoad:(UIWebView *)webView{
self.webView.hidden = TRUE;
}
- (void)webViewDidFinishLoad: (UIWebView *) webView {
[self useJScript:self.webView];
NSLog(@"Show %@", self.webView);//result above^^^
self.webView.hidden = FALSE;
NSLog(@"Showned %@", self.webView);
}
- (void)useJScript:(UIWebView *) webView{
NSLog(@"Применяю jscript для %@",webView);
NSString *path = [[NSBundle mainBundle] pathForResource:@"jsmain" ofType:@"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData:
[readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
[webView stringByEvaluatingJavaScriptFromString:htmlString];
}
It's not straightforward but it works:
We can show webView after webViewDidFinishLoad method and take 0.2 sec(it doesn't matter for user) to finish JScript in it.
Just add [self performSelector:@selector(hidden_false) withObject:nil afterDelay:0.2 ];
to webViewDidFinishLoad
method. And
-(void) hidden_false{
self.webView.hidden = FALSE;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}