[英]UIWebView - crash when dismissing modal view controller while request is in progress
嘿所有,我提出了一个模态视图控制器,并在UIWebView中的该视图控制器上加载一个网页:
- (void)viewWillAppear:(BOOL)animated
{
self.requestObj = [NSURLRequest requestWithURL:[NSURL URLWithString:[MPServerPrefs serverPrefs].url_of_sandwich]];
[self.helpWebView loadRequest:self.requestObj];
}
如果我让网页加载然后关闭视图,一切正常。 如果我在加载请求时关闭视图,我会得到这个堆栈跟踪:
#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:]
我做了一些搜索,无法弄清楚发生了什么。 有任何想法吗? 在解雇视图控制器时是否需要取消我的请求?
非常感谢!
傻傻的我 - 你只需要取消请求就可以取消代表!
[self.helpWebView setDelegate:nil];
[self.helpWebView stopLoading];
您的请求正在主线程上运行。 请求是否会使您的UI挂起? 如果您必须等待请求在其余代码执行之前完成,那么您的用户将不知道在视图等待加载时发生了什么。 尝试在单独的线程上运行请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.