这个问题有点不言自明,但无论如何我都会解释它。出于某种原因,当我尝试加载新网页时,它会看到网页 URL,但在您第一次按下按钮时它不会加载它。只有当您再次按下按钮时,它才会真正加载。我该如何解决这个问题?
这是我的按钮的代码:
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]]];
*另请注意,即使我在此处复制网页然后从文件加载它,如果我只是从 URL 加载它,我仍然会遇到同样的问题。
试试这个:
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];