2

我在加载URL时遇到了非常小的问题UIWebView。我有一个UIButton,单击它时,我添加了UIView其中包含UIWebView, UIButton& 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我在 object 中传递的内容objWine.strOnlineURL。如果我单击后退按钮并再次单击按钮以加载,它将URL进入. 如果有人知道解决方案,请帮助我。- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)errorUIWebView

4

3 回答 3

3

当您要返回时,向 nil 提出请求并将空加载htmlstringwebview. 还有一件事,[indicator removeFromSuperview];

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 
-(void)webViewDidFinishLoad:(UIWebView *)webView
于 2013-01-10T11:44:42.767 回答
1

而不是每次都添加您webview的点击。button为什么不将您的添加webview到您的和viewDidLoad点击中hideshowbutton

于 2013-01-10T11:31:47.210 回答
0

采用

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

如果它工作正常然后检查objWine.strOnlineURL

否则很清楚:)

于 2013-01-10T11:14:09.907 回答