嘿所有,我正在呈现一个模态视图控制器并在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:]
我做了一些搜索,无法弄清楚发生了什么 . 有任何想法吗?在解雇视图控制器时是否需要取消我的请求?
非常感谢!
2 回答
傻傻的我 - 你只需要取消请求就可以取消代表!
您的请求正在主线程上运行 . 请求是否会使您的UI挂起?如果在执行其余代码之前必须等待请求完成,那么在视图等待加载时,您的用户将不知道发生了什么 . 尝试在单独的线程上运行请求 .