本文介绍了ios:Webview委托的EXC_BAD_ACCESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我正在尝试解决这些Crashlytics问题,我有这个崩溃日志

I have a situation where I am trying to resolve these Crashlytics issues and I have this crash log

Thread : Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x34217f46 objc_msgSend + 5
1  UIKit                          0x29a2d5a3 -[UIWebView webView:decidePolicyForNavigationAction:request:frame:decisionListener:] + 182
2  CoreFoundation                 0x2630cad4 __invoking___ + 68
3  CoreFoundation                 0x26239645 -[NSInvocation invoke] + 300
4  CoreFoundation                 0x2623d0c7 -[NSInvocation invokeWithTarget:] + 50
5  WebKitLegacy                   0x326d9261 -[_WebSafeForwarder forwardInvocation:] + 224
6  CoreFoundation                 0x2630b62f ___forwarding___ + 354
7  CoreFoundation                 0x2623d008 _CF_forwarding_prep_0 + 24
8  CoreFoundation                 0x2630cad4 __invoking___ + 68
9  CoreFoundation                 0x26239645 -[NSInvocation invoke] + 300
10 WebCore                        0x31c02729 HandleDelegateSource(void*) + 100
11 CoreFoundation                 0x262cefbf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
12 CoreFoundation                 0x262ce461 __CFRunLoopDoSources0 + 364
13 CoreFoundation                 0x262cca35 __CFRunLoopRun + 772
14 CoreFoundation                 0x2621a3b1 CFRunLoopRunSpecific + 476
15 CoreFoundation                 0x2621a1c3 CFRunLoopRunInMode + 106
16 GraphicsServices               0x2d801201 GSEventRunModal + 136
17 UIKit                          0x2988443d UIApplicationMain + 1440
18 abc                          0x0030dcd7 main (main.m:14)

我可以理解它在webview委托上的一些回调和坏的超额已经发生,所以要纠正我通过

I can understand that its some callback on webview delegate and bad excess has occurred, so to rectify this I handled the delegates via

[self.webview stopLoading];
self.webview.delegate =nil;

但我可以看到这次崩溃。你能告诉我可能出现的问题以及纠正这种情况的一些方法吗?

in all the classes, yet I can see this crash. Can you enlighten me what's possibly going wrong and some approach to rectify this?

推荐答案

以下可能是这种情况


  • 向用户显示一个屏幕,其中包含 UIWebView

  • 委托网页开始下载时, UIViewController 设置 self

  • 用户退出屏幕

  • UIViewController 获取解除分配 UIWebView 完成加载并发送我已完成加载消息到委托

  • The user is presented a screen with UIWebView
  • The UIViewController sets self as the delegate Web page starts downloading
  • The User quits screen
  • UIViewController gets deallocated UIWebView finishes loading and sends I am finished loading message to its delegate

当webview对象没有更多时,会调用其他一些委托方法。悬空指针效果

some other delegate method gets called when the webview object is no more.i.e dangling pointer effect

1.在离开视图之前,始终确保停止加载webView 删除委托

1.Always make sure you stop loading the webView and remove the delegate before leaving the view

这里是

// If ARC is used
- (void)dealloc {
    [_webView setDelegate:nil];
    [_webView stopLoading];
}

// If ARC is not used
- (void)dealloc {
    [webView setDelegate:nil];
    [webView stopLoading];
    [webView release];
    [super dealloc];
}

// ARC - Before iOS6 as its deprecated from it.
- (void)viewWillUnload {
    [webView setDelegate:nil];
    [webView stopLoading];
}

2.确保你不是 stopLoading setDelegate 中为nil viewWillDisappear

2.Make sure you are not stopLoading and setDelegate to nil in viewWillDisappear

如果 ViewController是另一个ViewController 的子节点,你可以
从删除ViewController的视图 em> parent
带有动画的ViewController视图。同时,你可以
从其父级删除ViewController,并从 c> c> c中删除其引用。此时
ViewController nil viewWillDisappear
永远不会被称为,这意味着 WebView代表永远不会被
清理

使用 dealloc 并确保始终清理 WebView

3.确保设置 子视图的 ContentOffset webview CGPointZero 无动画

3.Make sure you set the ContentOffset of the subviews of webview to CGPointZero without animation

所以最好在关闭之前调用父视图控制器中的以下代码

so its better to you call the following code of in parent viewcontroller before closing it

 for (id subview in webView.subviews){
        if ([[subview class] isSubclassOfClass: [UIScrollView class]]){
            [subview setContentOffset:CGPointZero animated:NO];
        }
    }

希望这会有所帮助。请随意询问您的疑问。

Hope this helps.Feel free to ask your doubts.

4.一般来说,你不应该嵌入 UIWebView <$ c $中的对象c> UIScrollView 对象。如果这样做,可能会导致意外行为,因为两个对象的触摸事件可能会混淆并被错误处理。

4.Generally speaking You should not embed UIWebView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

以下是

这篇关于ios:Webview委托的EXC_BAD_ACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 03:18