UIWebView - 在请求正在进行时关闭模态视图控制器时崩溃
嘿大家, 我正在呈现一个模式视图控制器,并在 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:]
我做了一些搜索,但无法弄清楚发生了什么。有什么想法吗?关闭视图控制器时是否需要取消请求?
非常感谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
愚蠢的我 - 你只需要取消请求并取消委托!
Silly me - you just need to cancel the request and nil out the delegate!
您的请求正在主线程上运行。该请求是否会使您的 UI 挂起?如果您必须等待请求完成才能执行其余代码,那么您的用户将想知道视图等待加载时发生了什么。尝试在单独的线程上运行该请求。
Your request is running on the main thread. Does the request make your UI hang? If you have to wait for the request to finish before the rest of the code executes, your user will be left wondering what's going on while the view is waiting to load. Try running the request on a separate thread.