iOS UIWebView TextField - 输入文本后,键盘上的Done按钮应用程序崩溃

时间:2016-09-09 13:47:22

标签: ios swift uiwebview

我的应用中有几个网页浏览量。很少有网络视图会包含文本字段。

最初运行应用程序时,在文本字段中输入一些文本并点击键盘上的“完成”按钮会导致应用程序崩溃。如果我重新启动应用程序并尝试相同的方案,它可以正常工作。

我在WebView中也运行了很少的Javascript文件。

这是抛出的错误:

EXC_BAD_ACCESS mh_execute_header
Attempted to dereference null pointer.

这是我从崩溃细节中得到的痕迹:

/usr/lib/libobjc.A.dylib:0objc_msgSend  
Frameworks/UIKit.framework/UIKit:0-[_UIWebViewScrollViewDelegateForwarder forwardInvocation:]   
Frameworks/CoreFoundation.framework/CoreFoundation:0___forwarding___    
Frameworks/CoreFoundation.framework/CoreFoundation:0__forwarding_prep_0___  
Frameworks/UIKit.framework/UIKit:0-[UIScrollView _getDelegateZoomView]  
Frameworks/UIKit.framework/UIKit:0-[UIScrollView _zoomScaleFromPresentationLayer:]  
Frameworks/UIKit.framework/UIKit:0-[UIWebDocumentView _zoomedDocumentScale] 
Frameworks/UIKit.framework/UIKit:0-[UIWebDocumentView _layoutRectForFixedPositionObjects]   
Frameworks/UIKit.framework/UIKit:0-[UIWebDocumentView _updateFixedPositionedObjectsLayoutRectUsingWebThread:synchronize:]   
Frameworks/UIKit.framework/UIKit:0-[UIWebDocumentView _updateFixedPositioningObjectsLayoutAfterScroll]  
Frameworks/UIKit.framework/UIKit:0-[UIWebBrowserView _updateFixedPositioningObjectsLayoutAfterScroll]   
Frameworks/CoreFoundation.framework/CoreFoundation:0__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__  
Frameworks/CoreFoundation.framework/CoreFoundation:0_CFXRegistrationPost    
Frameworks/CoreFoundation.framework/CoreFoundation:0___CFXNotificationPost_block_invoke 
Frameworks/CoreFoundation.framework/CoreFoundation:0-[_CFXNotificationRegistrar find:object:observer:enumerator:]   
Frameworks/CoreFoundation.framework/CoreFoundation:0_CFXNotificationPost    
Frameworks/Foundation.framework/Foundation:0-[NSNotificationCenter postNotificationName:object:userInfo:]   
Frameworks/UIKit.framework/UIKit:0-[UIInputWindowController postEndNotifications:withInfo:] 
Frameworks/UIKit.framework/UIKit:0__77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke_2896   
Frameworks/UIKit.framework/UIKit:0-[UIInputWindowController performWithSafeTransitionFrames:]   
Frameworks/UIKit.framework/UIKit:0__77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke887 
Frameworks/UIKit.framework/UIKit:0-[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:]   
Frameworks/UIKit.framework/UIKit:0-[UIViewAnimationState sendDelegateAnimationDidStop:finished:]    
Frameworks/UIKit.framework/UIKit:0-[UIViewAnimationState animationDidStop:finished:]    
Frameworks/QuartzCore.framework/QuartzCore:0<redacted>  
/usr/lib/system/libdispatch.dylib:0_dispatch_client_callout 
/usr/lib/system/libdispatch.dylib:0_dispatch_main_queue_callback_4CF    
Frameworks/CoreFoundation.framework/CoreFoundation:0__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__  
Frameworks/CoreFoundation.framework/CoreFoundation:0__CFRunLoopRun  
Frameworks/CoreFoundation.framework/CoreFoundation:0CFRunLoopRunSpecific    
PrivateFrameworks/GraphicsServices.framework/GraphicsServices:0GSEventRunModal  
Frameworks/UIKit.framework/UIKit:0-[UIApplication runModal:]    
Frameworks/UIKit.framework/UIKit:0-[UIAlertView _showAnimated:] 
Frameworks/UIKit.framework/UIKit:0-[UIWebView webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:] 
Frameworks/CoreFoundation.framework/CoreFoundation:0__invoking___   
Frameworks/CoreFoundation.framework/CoreFoundation:0-[NSInvocation invoke]  
Frameworks/CoreFoundation.framework/CoreFoundation:0-[NSInvocation invokeWithTarget:]   
PrivateFrameworks/WebKitLegacy.framework/WebKitLegacy:0<redacted>   
Frameworks/CoreFoundation.framework/CoreFoundation:0___forwarding___    
Frameworks/CoreFoundation.framework/CoreFoundation:0__forwarding_prep_0___  
PrivateFrameworks/WebKitLegacy.framework/WebKitLegacy:0<redacted>   
PrivateFrameworks/WebCore.framework/WebCore:0<redacted> 
PrivateFrameworks/WebCore.framework/WebCore:0<redacted> 
Frameworks/JavaScriptCore.framework/JavaScriptCore:0<redacted>  
Frameworks/JavaScriptCore.framework/JavaScriptCore:0<redacted>  
Frameworks/JavaScriptCore.framework/JavaScriptCore:0<redacted>  
Frameworks/JavaScriptCore.framework/JavaScriptCore:0<redacted>  
Frameworks/JavaScriptCore.framework/JavaScriptCore:0<redacted>  
Frameworks/JavaScriptCore.framework/JavaScriptCore:0<redacted>  
Frameworks/JavaScriptCore.framework/JavaScriptCore:0<redacted>  
Frameworks/JavaScriptCore.framework/JavaScriptCore:0JSC::call(JSC::ExecState*, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&, WTF::NakedPtr<JSC::Exception>&)    
PrivateFrameworks/WebCore.framework/WebCore:0<redacted> 
PrivateFrameworks/WebCore.framework/WebCore:0<redacted> 
PrivateFrameworks/WebCore.framework/WebCore:0<redacted> 
PrivateFrameworks/WebCore.framework/WebCore:0<redacted> 
PrivateFrameworks/WebCore.framework/WebCore:0<redacted> 
PrivateFrameworks/WebCore.framework/WebCore:0<redacted> 
PrivateFrameworks/WebCore.framework/WebCore:0WebCore::EventHandler::keyEvent(WebCore::PlatformKeyboardEvent const&) 
PrivateFrameworks/WebCore.framework/WebCore:0WebCore::EventHandler::keyEvent(WebEvent*) 
Frameworks/CoreFoundation.framework/CoreFoundation:0__invoking___   
Frameworks/CoreFoundation.framework/CoreFoundation:0-[NSInvocation invoke]  
Frameworks/CoreFoundation.framework/CoreFoundation:0-[NSInvocation invokeWithTarget:]   
Frameworks/UIKit.framework/UIKit:0-[UIThreadSafeNode forwardInvocation:]    
Frameworks/CoreFoundation.framework/CoreFoundation:0___forwarding___    
Frameworks/CoreFoundation.framework/CoreFoundation:0__forwarding_prep_0___  
Frameworks/UIKit.framework/UIKit:0-[UIKeyboardImpl _handleWebKeyEvent:withEventType:withInputString:withInputStringIgnoringModifiers:]  
Frameworks/UIKit.framework/UIKit:0__78-[UIKeyboardImpl _handleWebKeyEvent:withIndex:inInputString:executionContext:]_block_invoke   
Frameworks/UIKit.framework/UIKit:0-[UIKeyboardTaskExecutionContext returnExecutionToParentWithInfo:]    
Frameworks/UIKit.framework/UIKit:0-[UIKeyboardTaskExecutionContext returnExecutionToParentWithInfo:]    
Frameworks/UIKit.framework/UIKit:0-[UIKeyboardTaskQueue continueExecutionOnMainThread]  
Frameworks/Foundation.framework/Foundation:0__NSThreadPerformPerform    
Frameworks/CoreFoundation.framework/CoreFoundation:0__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__  
Frameworks/CoreFoundation.framework/CoreFoundation:0__CFRunLoopDoSources0   
Frameworks/CoreFoundation.framework/CoreFoundation:0__CFRunLoopRun  
Frameworks/CoreFoundation.framework/CoreFoundation:0CFRunLoopRunSpecific    
PrivateFrameworks/GraphicsServices.framework/GraphicsServices:0GSEventRunModal  
Frameworks/UIKit.framework/UIKit:0UIApplicationMain 
MyApp:0mh_execute_header    
/usr/lib/system/libdyld.dylib:0<redacted>

我真的不确定为什么会发生这种崩溃。

TIA!

1 个答案:

答案 0 :(得分:0)

通过执行以下操作,我能够解决此问题:

  1. 解除键盘时放置Javascript回调
  2. 中获取回调

    func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool

    1. 设置WebView的ScrollView的内容偏移量:
    2. webView.scrollView.setContentOffset(CGPointMake(0, 0), animated: false)

      我在ScrollView中有一堆WebView。我知道这不太理想,但我必须继续这样做。

      当键盘被解除时,WebView会尝试滚动到不存在的位置并导致应用程序崩溃。

      因此,通过执行回调方法,一旦键盘被解除,我就将WebView滚动到顶部。

相关问题