1

在我的应用程序中,我使用 UIWebview 呈现 HTML5 网站。当我选择一个下拉菜单时,会出现一个带有嵌入式 UITableView 的弹出框。在表格视图中选择条目时,JS 会加载数据。似乎 Webkit 在主线程中同步加载数据。下面提供了堆栈跟踪。这会导致主线程挂起一段时间并冻结 UI。

我遵循 UIWebview 指南,在主线程上创建 Web 视图。

相同的网站在 Mobile Safari 上运行良好。任何帮助表示赞赏。

#0  0x3367e004 in mach_msg_trap ()
#1  0x3367e200 in mach_msg ()
#2  0x3589a3f2 in __CFRunLoopServiceMachPort ()
#3  0x3589912a in __CFRunLoopRun ()
#4  0x3581c4a4 in CFRunLoopRunSpecific ()
#5  0x3581c36c in CFRunLoopRunInMode ()
#6  0x33edd7ca in WebCore::ResourceHandle::loadResourceSynchronously ()
#7  0x33bf5c04 in WebCore::FrameLoader::loadResourceSynchronously ()
#8  0x339ebd5a in WebCore::DocumentThreadableLoader::loadRequest ()
#9  0x339eb984 in WebCore::DocumentThreadableLoader::DocumentThreadableLoader ()
#10 0x33b65fd4 in WebCore::DocumentThreadableLoader::loadResourceSynchronously ()
#11 0x33f4880a in WebCore::ThreadableLoader::loadResourceSynchronously ()
#12 0x339eb5bc in WebCore::XMLHttpRequest::createRequest ()
#13 0x339eb35a in WebCore::XMLHttpRequest::send ()
#14 0x339eaeea in WebCore::JSXMLHttpRequest::send ()
#15 0x339ead98 in WebCore::jsXMLHttpRequestPrototypeFunctionSend ()
#16 0x356de598 in JSC::Interpreter::privateExecute ()
#17 0x3575d0ec in JSC::Interpreter::executeCall ()
#18 0x3575ccd0 in JSC::call ()
#19 0x339d5f0e in WebCore::JSEventListener::handleEvent ()
#20 0x339d5bd2 in WebCore::EventTarget::fireEventListeners ()
#21 0x338dc7c6 in WebCore::EventTarget::fireEventListeners ()
#22 0x338e2d38 in WebCore::Node::handleLocalEvents ()
#23 0x338e2588 in WebCore::EventDispatcher::dispatchEvent ()
#24 0x338e233a in WebCore::EventDispatchMediator::dispatchEvent ()
#25 0x338e230e in WebCore::EventDispatcher::dispatchEvent ()
#26 0x338e2266 in WebCore::Node::dispatchEvent ()
#27 0x33e757f4 in WebCore::Node::dispatchChangeEvent ()
#28 0x33c278aa in WebCore::HTMLFormControlElement::dispatchFormControlChangeEvent ()
#29 0x33eeb7a8 in WebCore::SelectElement::menuListOnChange ()
#30 0x33eeb7be in WebCore::SelectElement::dispatchBlurEvent ()
#31 0x33c35670 in WebCore::HTMLSelectElement::dispatchBlurEvent ()
#32 0x338e1a4e in WebCore::Document::setFocusedNode ()
#33 0x338e1788 in WebCore::FocusController::setFocusedNode ()
#34 0x33bdfdfe in WebCore::Element::blur ()
#35 0x33b802d0 in -[DOMElement blur] ()
#36 0x358c97e4 in __invoking___ ()
#37 0x358247b0 in -[NSInvocation invoke] ()
#38 0x358243ce in -[NSInvocation invokeWithTarget:] ()
#39 0x306824c0 in -[UIThreadSafeNode forwardInvocation:] ()
#40 0x358c8a82 in ___forwarding___ ()
#41 0x35823650 in __forwarding_prep_0___ ()
#42 0x30511acc in -[UIWebBrowserView resignFirstResponder] ()
#43 0x305e6658 in -[UIWebSelectTableViewController tableView:didSelectRowAtIndexPath:] ()
#44 0x3047bae4 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] ()
#45 0x304f57aa in -[UITableView _userSelectRowAtPendingSelectionIndexPath:] ()
#46 0x346ad932 in __NSFireDelayedPerform ()
#47 0x3589aa32 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#48 0x3589a698 in __CFRunLoopDoTimer ()
#49 0x3589926e in __CFRunLoopRun ()
#50 0x3581c4a4 in CFRunLoopRunSpecific ()
#51 0x3581c36c in CFRunLoopRunInMode ()
#52 0x3559b438 in GSEventRunModal ()
#53 0x303f7e7c in UIApplicationMain ()
4

1 回答 1

0

您能否更具体地说明您是如何调用请求并将数据传递到 UIWebView 的?

比如:你有没有设置UIWebViewDelegate来控制willStartLoading和didFinishLoading?您是否将 NSURLRequest 设置为同步或异步?

通常,委托在单独的线程上加载 UIWebView,这样 main 就不会被阻塞。我认为您需要在某些参数上做更多的工作才能使其正确。

于 2012-06-07T04:58:12.410 回答