UIWebView不加载URL

时间:2013-01-10 11:06:40

标签: iphone ios objective-c uiwebview

我在UIWebView中加载网址时遇到的问题非常小。 我有一个UIButton,点击它后,我添加UIView,其中包含UIWebViewUIButton& Title bar。使用的代码如下 -

    [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的大部分时间都不会加载我在对象URL中传递的objWine.strOnlineURL。如果我点击后退按钮&再次单击按钮以加载URL,它将进入- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error UIWebView委托方法。 如果有人知道解决方案,请帮助我。

3 个答案:

答案 0 :(得分:3)

当您返回时,请求nil并将空htmlstring加载到webview。还有一件事,从

中删除[indicator removeFromSuperview];
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 
-(void)webViewDidFinishLoad:(UIWebView *)webView

答案 1 :(得分:1)

不是每次都在webview点击上添加button。为什么不在webview点击中将viewDidLoad添加到hideshow以及button

答案 2 :(得分:0)

使用

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com"]];

如果工作正常,请检查objWine.strOnlineURL

否则很清楚:)