大家好, 我正在展示一个模态视图 Controller 并在 UIWebView 中的该 View Controller 上加载一个网页:
- (void)viewWillAppear:(BOOL)animated
{
self.requestObj = [NSURLRequest requestWithURL:[NSURL URLWithString:[MPServerPrefs serverPrefs].url_of_sandwich]];
[self.helpWebView loadRequest:self.requestObj];
}
如果我让网页加载然后关闭 View ,一切正常。如果我在加载请求时关闭 View ,我会得到这个堆栈跟踪:
#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:]
我做了一些搜索,但无法弄清楚发生了什么。有任何想法吗?关闭 View Controller 时是否需要取消我的请求?
非常感谢!
最佳答案
愚蠢的我 - 你只需要取消请求并取消委托(delegate)!
[self.helpWebView setDelegate:nil];
[self.helpWebView stopLoading];
关于ios - UIWebView - 在请求正在进行时关闭模态视图 Controller 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5738589/