UIWebView不加载URL [英] UIWebView does not load the URL
问题描述
在 UIWebView
中加载网址时,我遇到的问题非常小。
我有一个 UIButton
,点击它,我添加 UIView
,其中包含 UIWebView
, UIButton
& 标题栏
。使用的代码如下 -
I have very small problem while loading the URL in UIWebView
.
I have one UIButton
, on clicking of it, I add the UIView
which contains UIWebView
, UIButton
& Title bar
. Code used is as follows -
[self.view addSubview:vwOnline];
vwOnline.bounds = self.view.bounds;
//Load webview
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", objWine.strOnlineURL]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[wbvwOnline loadRequest:request];
- (void)webViewDidStartLoad:(UIWebView *)webView
{
//Show activity indicator
[indicator startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//Remove Activity indicator
[indicator stopAnimating];
[indicator removeFromSuperview];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"Error - %@", error);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Find A Vino" message:@"Error while loading request." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
alert.tag = 1;
//Remove Activity indicator
[indicator stopAnimating];
[indicator removeFromSuperview];
}
通过上面的代码,大部分时间是 UIWebView
不会加载我在对象 objWine.strOnlineURL
中传递的 URL
。如果我点击后退按钮&再次单击按钮加载 URL
,它进入 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)错误
UIWebView
的委托方法。
如果有人知道解决方案,那么请帮助我。
By doing above code, most of times the UIWebView
does not loads the URL
which I passed in the object objWine.strOnlineURL
. If I clicked the back button & again clicked on the button to load the URL
, it goes into the - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
delegate method of UIWebView
.
If anyone knows the solution, then please help me.
推荐答案
当你回去时,请求零并将 htmlstring
加载到 webview
。还有一件事,删除 [指标removeFromSuperview];
行
when you are going back, make request to nil and load empty htmlstring
to webview
. One more thing, remove [indicator removeFromSuperview];
line from
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
-(void)webViewDidFinishLoad:(UIWebView *)webView
这篇关于UIWebView不加载URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!