UIWebView - 在请求正在进行时关闭模态视图控制器时崩溃

发布于 2024-11-02 18:20:37 字数 838 浏览 1 评论 0原文

嘿大家, 我正在呈现一个模式视图控制器,并在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一刻暧昧 2024-11-09 18:20:37

愚蠢的我 - 你只需要取消请求并取消委托!

[self.helpWebView setDelegate:nil];
[self.helpWebView stopLoading];

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

[self.helpWebView setDelegate:nil];
[self.helpWebView stopLoading];
我爱人 2024-11-09 18:20:37

您的请求正在主线程上运行。该请求是否会使您的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文