簡體   English   中英

UIWebView - 在請求正在進行時解除模態視圖控制器時崩潰

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM