简体   繁体   English

如何修复第二次而不是第一次加载的Webview?

[英]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.

相关问题 如何存储我的第一个文本字段以免第二次快速查询 - How to store my first textfield to not ask for the second time in swift 如何在 ios 中加载 webview url 之前执行任务? - how do I perform tasks before loading a webview url in ios? Xcode:我的用户位置在第一次运行模拟时没有显示,但是在第二次运行时显示 - Xcode: My user location doesn't show the first time I run the simulation but the second time it does 如何交换字符串数组中的第一项和第二项? - How do I swap the first and second items in an array of strings? 如何确定我的应用是第一次从AppStore下载? - How do I determine that my app was just downloaded from AppStore the first time? 为什么我的数组第二次为空,当我将它的第一个对象分配给目标C中的字典时,ios - why my array is null in second time, when I assigned it's first object to dictionay in objective C, ios 如何修复 Table Viewcontroller 上的时间延迟? - How can I fix a time delay on my Table Viewcontroller? 如何在第二个选项卡中将managedObjectContext传递给tablecontroller? - How do I pass a managedObjectContext to the tablecontroller in my second tab? 两个UIWebViews,如何设置第二个webview,以便在单击链接时将它们发送到第一个要加载的webview? - Two UIWebViews, how to set the second webview so when links are clicked it sends them to the first webview to load? iPhone-Webview中的页面加载时间 - iPhone - Page loading time in webview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM