Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView - crash when dismissing modal view controller while request is in progress

Hey all, I am presenting a modal view controller and loading a webpage on that view controller in a UIWebView:

- (void)viewWillAppear:(BOOL)animated
{
     self.requestObj = [NSURLRequest requestWithURL:[NSURL URLWithString:[MPServerPrefs serverPrefs].url_of_sandwich]];
     [self.helpWebView loadRequest:self.requestObj];
}

Everything works fine if I let the webpage load and then dismiss the view. If I dismiss the view while the request is loading, I get this stacktrace:

#0  0x31a94466 in objc_msgSend
#1  0x35ebcb70 in -[UIWebView webView:identifierForInitialRequest:fromDataSource:]
#2  0x35ebc1c0 in -[UIWebViewWebViewDelegate webView:identifierForInitialRequest:fromDataSource:]
#3  0x36130d04 in __invoking___
#4  0x36130bd4 in -[NSInvocation invoke]
#5  0x36130730 in -[NSInvocation invokeWithTarget:]
#6  0x329fc2f4 in -[_WebSafeForwarder forwardInvocation:]

I did some searching and can't figure out what's going on. Any ideas? Do I need to cancel my request when dismissing the view controller?

Many thanks!

like image 381
Mark Avatar asked Apr 21 '11 01:04

Mark


1 Answers

Silly me - you just need to cancel the request and nil out the delegate!

[self.helpWebView setDelegate:nil];
[self.helpWebView stopLoading];
like image 148
Mark Avatar answered Oct 12 '22 09:10

Mark