views:

301

answers:

2

I have a UIWebView named wView. I want to use webViewDidFinishLoad: in my class, so I am setting the class as the delegate for wView by using this line:

wView.delegate = self;

Everything loads properly, but when I close the UIWebView, the App crashes. If I comment out the wView.delegate = self, it works and does not crash, but then I can't use webViewDidFinishLoad: - any ideas? Do I need to release something?

+2  A: 

The UIWebView Reference says:

Important: Before releasing an instance of UIWebView for which you have set a delegate, you must first set its delegate property to nil. This can be done, for example, in your dealloc method.

David Gelhar
A: 

Ensure to set the delegate to nil (wView.delegate = nil). This will prevent webview from trying to access and call methods on a dealloc'd view controller, which would result in a crash.

raidfive