Close the web pageView after loading

1

I'm using webView on iOS to access a web page within a native application using the objective-c language as in the following example:

NSURL *url = [NSURL URLWithString:@"http://www.exemplo.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];

But I would like the page to be fully loaded if it automatically closes without the user having to interfere. I already looked in the NSURL documentation, but I did not find anything to help me with this.

    
asked by anonymous 09.10.2015 / 14:39

2 answers

1

First, add in your header file .h the delegate class for UIWebView :

@interface WebViewController : UIViewController <UIWebViewDelegate>

And so, in the implementation set the ownership of your UIWebView :

[_webView setDelegate:self];

And finally, the delegate method that will perform the action you want as soon as the page loads:

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    // Ação ao carregar página...
}

By "close the page", I do not quite understand what exactly this action you want, but I believe that from this method you can define.

    
09.10.2015 / 14:57
0

In addition to using the delegate method of webView: webViewDidFinishLoad

- (void)webViewDidFinishLoad:(UIWebView *)webView {
     // Ação chamada ao terminar de carregar a página...

    // Recomendo adicionalmente uma ação para ser executada automaticamente após alguns segundos depois de carregada a pagina, seja para ocultar a webview ou apresentar uma mensagem ao usuário dizendo que foi com sucesso.
    [self performSelector:@selector(hideWebView) withObject:nil afterDelay:2.0];
}

Also use the delegate method to handle page load error situations!

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    //Trate os possíveis erros da carga da url aqui.
}
    
20.10.2015 / 02:41