Categories: Sviluppo

Clear a WebView before loading a new URL

It seems there isn’t a direct way to clear the content of a WebView before loading a new URL. If you have a TableView and every cell contains a link which push a WebView to display a link, the web previously loaded is display until the new link start loading.
The best way I found to clear out the previous content is to load an empty html file (stored on the resources) on the viewWillDisappear as in the following code:

- (void)viewWillDisappear:(BOOL)animated {
 [super viewWillDisappear:animated];
 
 NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"blank" ofType:@"html" ]; 
 NSURL *url = [[NSURL alloc] initFileURLWithPath: htmlPath]; 
 NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url]; 
 [myWebView loadRequest: request]; 
 [request release]; 
 [url release];
}
Paolo

Share
Published by
Paolo
Tags: Tips&Triks

Recent Posts

Ogrodnistwo

https://youtu.be/ikhG3K3KRk8 Peppa: Jestem świnka Peppa. To mój mały brat George. To mama świnka. A to…

3 anni ago

Zagubione okulary taty

https://www.youtube.com/watch?v=uhHHH8GqxK4 Peppa: Jestem świnka Peppa. To mój mały brat George. To mama świnka. A to…

3 anni ago

Świnka w środku

https://www.youtube.com/watch?v=iD4XxFky5e4 Peppa: Jestem świnka Peppa. To mój mały brat George. To mama świnka. A to…

3 anni ago

Mama świnka w pracy

https://youtu.be/KDYDkS4mVuw Peppa: Jestem świnka Peppa. To mój mały brat George. To mama świnka. A to…

3 anni ago

Przedszkole

https://www.youtube.com/watch?v=TTi9aMd325s Peppa: Jestem świnka Peppa. To mój mały brat George. To mama świnka. A to…

3 anni ago

Auto elettrica? Per me ancora no ma ragioniamoci.

Dopo aver parlato di quella che ritengo disinformazione riguardo agli investimenti nei piani di accumulo,…

3 anni ago