26 Gennaio 2010

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];

Loved this? Spread the word

Articoli collegati

Alexa e le sue skill

Leggi Tutto

In arrivo Bus Torino 1.0 per Windows Phone 7

Leggi Tutto

Aggiornamenti di Bus Torino e Bus Torino Plus disponibili

Leggi Tutto

Rilascio della memoria degli outlet

Leggi Tutto
Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}