Chris
Chris

Reputation: 5627

Need to Release UIWebView Delegate?

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?

Upvotes: 0

Views: 1592

Answers (2)

raid5ive
raid5ive

Reputation: 6642

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.

Upvotes: 0

David Gelhar
David Gelhar

Reputation: 27900

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.

Upvotes: 4

Related Questions