2013-05-14 147 views
1

如果我在包含外部鏈接的UIWebView中調用loadHTMLString,然後嘗試重新加載HTMLString它崩潰。UIWebView崩潰加載鏈接從HTML

HTML載入如下:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"help" withExtension:@"html"]; 
    NSString *text = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil]; 

    [[self webView] loadHTMLString:text baseURL:nil]; 

help.html可以包含一個鏈接,如:

Example

如果我點擊它加載頁面的鏈接。但是我在導航欄上有一個「Home」按鈕,它再次調用上面的代碼(loadHTMLString),這會使應用程序崩潰。

任何方式來「欺騙」UIWebView在外部鏈接被查看後再次加載HTML字符串?

參考文獻: UIWebView won't goBack after loading HTML in iOS

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil' 

#0 0x906b29c6 in __pthread_kill() 
#1 0x9ca6ff78 in pthread_kill() 
#2 0x0399957b in abort() 
#3 0x03b19f7b in abort_message() 
#4 0x03b17a25 in default_terminate()() 
#5 0x035620c1 in _objc_terminate()() 
#6 0x03b17a65 in safe_handler_caller(void (*)())() 
#7 0x03b17acd in std::terminate()() 
#8 0x03b18bc2 in __cxa_throw() 
#9 0x03561f89 in objc_exception_throw() 
#10 0x03fd50de in -[__NSDictionaryM setObject:forKey:]() 
#11 0x03d485ce in -[WebHistoryPrivate visitedURL:withTitle:increaseVisitCount:]() 
#12 0x03d4a693 in -[WebHistory(WebInternal) _visitedURL:withTitle:method:wasFailure:increaseVisitCount:]() 
#13 0x03d394b5 in WebFrameLoaderClient::updateGlobalHistory()() 
#14 0x04db0747 in WebCore::HistoryController::replaceState(WTF::PassRefPtr<WebCore::SerializedScriptValue>, WTF::String const&, WTF::String const&)() 
#15 0x04dad610 in WebCore::History::stateObjectAdded(WTF::PassRefPtr<WebCore::SerializedScriptValue>, WTF::String const&, WTF::String const&, WebCore::History::StateObjectType, int&)() 
#16 0x0508041a in WebCore::JSHistory::replaceState(JSC::ExecState*)() 
#17 0x0507ec49 in WebCore::jsHistoryPrototypeFunctionReplaceState(JSC::ExecState*)() 
#18 0x0d892daf in 0x0d892daf() 
#19 0x08052e11 in JSC::Interpreter::executeCall(JSC::ExecState*, JSC::JSObject*, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&)() 
#20 0x07fabfc3 in JSC::call(JSC::ExecState*, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&)() 
#21 0x04f91d34 in WebCore::JSMainThreadExecState::call(JSC::ExecState*, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&)() 
#22 0x05064d15 in WebCore::JSEventListener::handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*)() 
#23 0x04ce9eac in WebCore::EventTarget::fireEventListeners(WebCore::Event*, WebCore::EventTargetData*, WTF::Vector<WebCore::RegisteredEventListener, 1ul>&)() 
#24 0x04ce9c76 in WebCore::EventTarget::fireEventListeners(WebCore::Event*)() 
#25 0x05333ce9 in WebCore::Node::handleLocalEvents(WebCore::Event*)() 
#26 0x04cd0419 in WebCore::EventDispatcher::dispatchEvent(WTF::PassRefPtr<WebCore::Event>)() 
#27 0x04cd16da in WebCore::EventDispatchMediator::dispatchEvent(WebCore::EventDispatcher*) const() 
#28 0x04ccf72e in WebCore::EventDispatcher::dispatchEvent(WebCore::Node*, WTF::PassRefPtr<WebCore::EventDispatchMediator>)() 
#29 0x05333eaa in WebCore::Node::dispatchEvent(WTF::PassRefPtr<WebCore::Event>)() 
#30 0x04bf85ad in WebCore::Document::finishedParsing()() 
#31 0x04e570ad in WebCore::HTMLTreeBuilder::finished()() 
#32 0x04dd4a9b in WebCore::HTMLDocumentParser::prepareToStopParsing()() 
#33 0x04c16a14 in WebCore::DocumentWriter::end()() 
#34 0x04c092a3 in WebCore::DocumentLoader::finishedLoading()() 
#35 0x052f6c22 in WebCore::MainResourceLoader::didFinishLoading(double)() 
#36 0x052f5c58 in WebCore::MainResourceLoader::continueAfterContentPolicy(WebCore::PolicyAction, WebCore::ResourceResponse const&)() 
#37 0x052f650e in WebCore::MainResourceLoader::didReceiveResponse(WebCore::ResourceResponse const&)() 
#38 0x052f4a58 in WebCore::MainResourceLoader::handleDataLoadNow(WebCore::Timer<WebCore::MainResourceLoader>*)() 
#39 0x052f8016 in WebCore::Timer<WebCore::MainResourceLoader>::fired()() 
#40 0x056e415c in WebCore::ThreadTimers::sharedTimerFiredInternal()() 
#41 0x056e4036 in WebCore::ThreadTimers::sharedTimerFired()() 
#42 0x05531c50 in WebCore::timerFired(__CFRunLoopTimer*, void*)() 
#43 0x03f11376 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__() 
#44 0x03f10e06 in __CFRunLoopDoTimer() 
#45 0x03ef8a82 in __CFRunLoopRun() 
#46 0x03ef7f44 in CFRunLoopRunSpecific() 
#47 0x03ef7e1b in CFRunLoopRunInMode() 
#48 0x05723c50 in RunWebThread(void*)() 
#49 0x9ca6ded9 in _pthread_start() 
+0

其他測試表明,該問題與jQuery手機有關。如果我用鏈接使用簡單的HTML文件,它不會崩潰。我計劃明天再追查一次。 – Christopher 2013-05-14 07:26:30

回答

0

以及它似乎是在UIWebview.The UIWebView的錯誤是不應該崩潰,即使TEH內容不存在或HTML錯誤occours.File錯誤

+0

是的,我認爲這是一個錯誤,因爲我可以每次重現它。 – Christopher 2013-05-14 07:00:03