[英]How do I fix my webview loading the second time and not the first?
This question is kind of self-explanatory but I'll explain it anyways. 这个问题有点不言自明,但是我还是会解释一下。 For some reason when I try and load a new web page it will see the web page URL except it won't load it the first time you press the button.
由于某些原因,当我尝试加载新的网页时,它将看到该网页的URL,但在您第一次按下按钮时不会加载它。 Only when you press the button again will it actually load.
只有再次按下该按钮时,它才会真正加载。 How do I fix this?
我该如何解决?
Here's the code for my button: 这是我的按钮的代码:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];
// Download and write to file
NSURL *url = [NSURL URLWithString:_varString];
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
//Load file in UIWebView
[_Hoot loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];
*Also note, even though I'm copying the web page here and then loading it from a file, I still get the same problem if I'm just loading it from a URL. *还请注意,即使我是在此处复制网页,然后从文件中加载网页,但是如果我只是从URL加载网页,仍然会遇到同样的问题。
Try this: 尝试这个:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];
// Download and write to file
NSURL *url = [NSURL URLWithString:_varString];
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
//Load file in UIWebView
NSURL *urlen = [NSURL fileURLWithPath:filePath];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:urlen];
[_Hoot loadRequest:urlRequest];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.