English 中文(简体)
如果电离层电离层电荷装上电离层,则进行检查。
原标题:Check if UIWebView is loaded

I have an UIWebView in one tab that loads in viewDidLoad, but if user taps other tab the loading will be disrupted and - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error will be called, but I want to know how can check if webView is loaded if user taps the previous tab again, and if it s not loaded it will reload it, something like this

  -(void)viewWillAppear:(BOOL)animated
{
    if (!webView)
        {
          NSURL *url = [NSURL URLWithString:@"url"];
          NSURLRequest *request = [NSURLRequest requestWithURL:url];
          [webView loadRequest:request];
        }

    }

但它没有工作,请帮助?

最佳回答

UIWebview有网络语言法。 为表明这一点,建立了一套工具。

- (void)webViewDidStartLoad:(UIWebView *)webView {

 webViewDidFinishLoadBool = NO;
 loadFailedBool = NO;

}


- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {

 loadFailedBool = YES;
}


- (void)webViewDidFinishLoad:(UIWebView *)webView {

   if (!loadFailedBool)
   webViewDidFinishLoadBool = YES;

}
问题回答

如果你不去工作,就是一个工作例子。 这还表明在无法装载时有警惕,警报只显示一次。

标题:

@interface MyViewController : UIViewController <UIWebViewDelegate> {
    BOOL wasLoaded;
    BOOL alertWasShown;
}

@property (nonatomic, retain) IBOutlet UIWebView *myWebView;

@end

Implementation:

- (void)loadWebView:(NSString *)urlString {
    if (wasLoaded == NO) {
        NSURL *url = [NSURL URLWithString:urlString];
        NSURLRequest *requestObject = [NSURLRequest requestWithURL:url];
        [myWebView loadRequest:requestObject];
    }
}

- (void)viewWillAppear:(BOOL)animated {
    NSString *urlString = @"put your url here";
    [self loadWebView:urlString];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    wasLoaded = NO;
    alertWasShown = NO;
    myWebView.delegate = self;
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    // Not necessary to do anything here.
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    wasLoaded = YES; // Indicates that it finished loading.
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    if (alertWasShown == NO) {
        UIAlertView *alert = ... // Create an alert.
        [alert show];

        alertWasShown = YES;
    }
}

我希望能够提供帮助。

It is true that the original question was posted many years ago. Recently I had to find a reliable solution to this issue.

这里的解决办法对我有利:

  1. Replaced UIWebView with WKWebWiew.
  2. Added evaluateJavaScript code while handling the didFinishNavigation delegate method.

完整的法典是:

   - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
    [webView evaluateJavaScript:@"document.body.innerHTML" completionHandler:^(id result, NSError *error) {
        if (result != nil) {
            // Call your method here
        }
        if(error) {
            NSLog(@"evaluateJavaScript error : %@", error.localizedDescription);
        }
    }];
}

For pages with multiple frames, UIWebView.loading property should also be used.

Apple s doc: @property(nonatomic, readonly, getter=isLoading) BOOL loading A Boolean value indicating whether the receiver is done loading content.

如果是YES,接收器仍在装载内容;否则,NO。

In iOS6 (beta 4) it looks like Apple has fixed some issues with this property as well. http://code-gotcha.blogspot.fi/2012/08/uiwebviewloading-in-ios-6-fixed.html





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签