UIWebView不会加载新请求
似乎无论我做什么,我都无法让 UIWebView 加载新的 URL。它收到加载请求,但我所做的任何事情似乎都没有真正使其执行任何操作。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
urlToVisit = [self.arrayOfURLs objectAtIndex:[indexPath row]];
[self dismissModalViewControllerAnimated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[WebViewToViewData loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlToVisit]]];
//[WebViewToViewData stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"location.href='%@''",urlToVisit]];
}
如您所见,我让它从字符串加载 URL(这是出于测试目的,但它不适用于任何内容)并且它接收请求,但不开始加载。我已经尝试过:
[WebViewToViewData reload];
但这没有任何作用。我什至无法让重新加载功能在任何地方工作。我可能做错了什么?
It seems no matter what I do, I can't get my UIWebView to load a new URL. It receives the load request, but nothing I do seems to actually make it do anything.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
urlToVisit = [self.arrayOfURLs objectAtIndex:[indexPath row]];
[self dismissModalViewControllerAnimated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[WebViewToViewData loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlToVisit]]];
//[WebViewToViewData stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"location.href='%@''",urlToVisit]];
}
as you can see, I have it loading the URL from a string (this is for testing purposes, but it doesn't work with anything) and it receives the request, but doesn't start loading. I've tried:
[WebViewToViewData reload];
and that doesn't do anything. I can't even get the reload function to work anywhere. What could I possibly be doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能需要检查 url 字符串是否包含空格或其他转义字符串并将其转换为百分比字符串。
you may need to check whether the url string contains space or other escape strings and convert them to percentage strings.
尝试一下
如果无法加载,请直接尝试 http://www.google.com/ 这样的简单网址而不是从数组中获取字符串,转换为 URL 并加载到 webView 中。
Try this
If that does'nt load, try simple url like http://www.google.com/ directly instead of taking strings from Array convert to URL and loading into webView.
我认为你需要定义一个协议来加载 webview。假设您从具有 webview 的主视图控制器呈现一个视图控制器。在第二个视图控制器中,您只有一个表视图。您正在尝试从第二个控制器加载 mainview 控制器中 webview 上的 url。如果所有这些假设都成立,则必须为此使用协议减速。
尝试此操作
第二个视图控制器 .h 文件中
您也可以在第一个视图控制器实现的.m 中的
,
I thing you need to define a protocol to load webview. Assuming that you present a view controller from main view controller which has the webview. In the second view controller you only have a table view. You are trying to load url on webview in mainview controller from second controller. If all these assumptions are true, you have to use protocol decleration for that.
Also you can try this
in second view controller .h file
in .m
in first view controller implement,
我将其设置为模态窗口,最后我所做的是将模态窗口更改为不同的动画,以便它会触发 viewDidAppear 并在其中包含该功能。至于来回发送值,我使用了 NSUserDefaults。
这是迄今为止我犯过的最愚蠢的错误。
I had it set to a Modal Window and what I ended up doing is changing the Modal window to a different animation so that it would fire viewDidAppear and have the function in there. As for sending the values back and forth and I used a NSUserDefaults.
This was by far the silliest error I've had.