【问题标题】:UIWebView loading stuff in AJAX blocks the main threadUIWebView 在 AJAX 中加载东西会阻塞主线程
【发布时间】:2023-03-31 12:48:01
【问题描述】:

我在加载页面的模式 viewController 中使用 webview。该页面最多可能需要 10 秒才能在 AJAX 中加载其内容。

如果在页面完全加载后关闭模态视图控制器,一切看起来都很好。但是,如果我在页面加载时关闭模式 viewController,则 UI 将完全锁定。当 UI 被锁定时,我暂停了调试,这是主线程中发生的事情:

Thread 1, Queue : com.apple.main-thread
#0  0x390b6fa8 in __psynch_mutexwait ()
#1  0x3911bf50 in _pthread_mutex_lock ()
#2  0x366ac60c in _WebTryThreadLock(bool) ()
#3  0x366ad434 in WebThreadLock ()
#4  0x31151cf8 in -[UIWebView dealloc] ()
#5  0x30f2f9b2 in -[UIView dealloc] ()
#6  0x30f2f9b2 in -[UIView dealloc] ()
#7  0x38b04022 in (anonymous namespace)::AutoreleasePoolPage::pop(void*) ()
#8  0x2e6de1c8 in _CFAutoreleasePoolPop ()
#9  0x2e773e82 in __CFRunLoopRun ()
#10 0x2e6de470 in CFRunLoopRunSpecific ()
#11 0x2e6de252 in CFRunLoopRunInMode ()
#12 0x334182ea in GSEventRunModal ()
#13 0x30f93844 in UIApplicationMain ()
#14 0x00017074 in main at /Users/.../main.m:16

UI 冻结大约 10 秒,这是页面需要加载的确切时间。

我在关闭模态视图控制器之前尝试调用 [_webview stopLoading] 但它没有帮助。

有谁知道这里发生了什么以及我应该做些什么来防止 webview 冻结 UI?谢谢

【问题讨论】:

  • 有同样的问题。似乎也无法弄清楚。

标签: ios objective-c uiwebview


【解决方案1】:

尝试在 UIWebView 上调用 -stopLoading,然后再在视图控制器上调用dismiss。

文档: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebView_Class/#//apple_ref/occ/instm/UIWebView/stopLoading

【讨论】:

  • 请完整阅读我的帖子:我已经解释过在关闭我的视图控制器之前调用 stopLoading 没有帮助
【解决方案2】:

原来是一些 CSS 属性导致了这个冻结。因此,如果您有同样的问题,并且如果您有幸能够访问 UIWebView 后面的页面,请尝试注释一些 CSS 属性,直到找到导致 webView 冻结的属性。

【讨论】:

    猜你喜欢
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多