ios - UIWebView - 在请求正在进行时关闭模态视图 Controller 时崩溃

标签 ios ios4 uikit uiwebview

大家好, 我正在展示一个模态视图 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/

相关文章:

ios - 创建第一个启动 View Controller

ios - 管理两个单元格之间的交换而不是更改其他 UITableViewcells 的 NSIndexpath

iPhone - 快速应用程序切换和 iOS 4

Swiftui - 从 UIViewRepresentable 访问 UIKit 方法/属性

ios - 如何同时翻转和旋转标签?

ios - 从 'JSON' 转换为无关类型 'String' 总是失败

ios - cgColor 和 UIColor 的区别

ios - UITextField secureTextEntry 带有自定义字体的项目符号?

ios - 如何使用键盘 "Go"像 Swift 2 中的 UIButton 一样提交 UITextFields

ios - 什么是注释:(id)annotation in openURL method?