0
  1. I hide webview in webViewDidStartLoad:
  2. Make request
  3. Make stringByEvaluatingJavaScriptFromString in webViewDidFinishLoad:
  4. Show webview

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];
}
kaspartus
  • 1,365
  • 15
  • 33

2 Answers2

0

Your fault is probably in the stringByEvaluatingJavaScriptFromString. Unless you show us some code, we won't be able to help you.

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
Lefteris
  • 14,550
  • 2
  • 56
  • 95
0

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;
}
kaspartus
  • 1,365
  • 15
  • 33