UIButton Clicked for Webview 加载到 ipad 后应用程序崩溃

Posted

技术标签:

【中文标题】UIButton Clicked for Webview 加载到 ipad 后应用程序崩溃【英文标题】:Application crash after UIButton Clicked for Webview load into ipad 【发布时间】:2012-07-02 06:39:29 【问题描述】:

我开发了一个应用程序,在其中我将一个视图控制器的视图添加到另一个视图控制器的视图中。 rootviewcontroller 有许多按钮,点击事件将不同的 viewcontroller 的视图添加到 rootviewcontroller 的视图中。其他按钮工作正常。但一个按钮使应用程序崩溃。 当我们点击那个按钮时,它会添加 viewconroller,它有一个 webview,其中加载了一个静态字符串。

if(interfaceOrientation != UIInterfaceOrientationPortrait && interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown)

    self.uiwebViewAboutUs = self.webview_ld;
    self.view = self.landscape_ipad;

else
    self.uiwebViewAboutUs = self.webview_pt;
    self.view = self.portrait_ipad;



-(void)viewDidAppear:(BOOL)animated

    [super viewDidAppear:animated];
    NSString *content = @"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.";
    [self.uiwebViewAboutUs loadhtmlString:content baseURL:nil];

崩溃报告在这里。

Incident Identifier: 211D86D5-F375-4CA7-B129-95D26A5E60A8
CrashReporter Key:   99eb9331f18d02387a15d4ad454c75a3cd14ea9e
Hardware Model:      iPad3,2
Process:         SunGroupWP [8334]
Path:            /var/mobile/Applications/F07B0EFA-0A65-4C63-A7EA-AB0D772CECD1/SunGroupWP.app/SunGroupWP
Identifier:      SunGroupWP
Version:         ??? (???)
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2012-06-30 09:37:58.489 -0700
OS Version:      iPhone OS 5.1.1 (9B206)
Report Version:  104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread:  0

Last Exception Backtrace:
0   CoreFoundation                  0x30d0888f __exceptionPreprocess + 163
1   libobjc.A.dylib                 0x362a5259 objc_exception_throw + 33
2   CoreFoundation                  0x30d08789 +[NSException raise:format:] + 1
3   CoreFoundation                  0x30d087ab +[NSException raise:format:] + 35
4   CoreFoundation                  0x30c7568b -[__NSCFDictionary setObject:forKey:] + 235
5   WebKit                          0x354f8043 -[WebPreferences _setStringValue:forKey:] + 151
6   UIKit                           0x32ab6e0b -[UIWebView _webViewCommonInit:] + 1547
7   UIKit                           0x32b54487 -[UIWebView initWithCoder:] + 99
8   Foundation                      0x35b98eaf _decodeObjectBinary + 2699
9   Foundation                      0x35b982f5 _decodeObject + 205
10  UIKit                           0x32b88811 -[UIRuntimeConnection initWithCoder:] + 113
11  Foundation                      0x35b98eaf _decodeObjectBinary + 2699
12  Foundation                      0x35b99a3b -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1103
13  Foundation                      0x35bba463 -[NSArray(NSArray) initWithCoder:] + 503
14  Foundation                      0x35b98eaf _decodeObjectBinary + 2699
15  Foundation                      0x35b982f5 _decodeObject + 205
16  UIKit                           0x32b87fc5 -[UINib instantiateWithOwner:options:] + 665
17  UIKit                           0x32af63c7 -[UIViewController _loadViewFromNibNamed:bundle:] + 247
18  UIKit                           0x329d3c59 -[UIViewController loadView] + 89
19  UIKit                           0x32949c17 -[UIViewController view] + 51
20  SunGroupWP                      0x0002de55 -[SampleDashBoardForIpad btnAboutClicked:] (SampleDashBoardForIpad.m:261)
21  CoreFoundation                  0x30c623fd -[NSObject performSelector:withObject:withObject:] + 53
22  UIKit                           0x3292be07 -[UIApplication sendAction:to:from:forEvent:] + 63
23  UIKit                           0x3292bdc3 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 31
24  UIKit                           0x3292bda1 -[UIControl sendAction:to:forEvent:] + 45
25  UIKit                           0x3292bb11 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 493
26  UIKit                           0x3292c449 -[UIControl touchesEnded:withEvent:] + 477
27  UIKit                           0x3292a92b -[UIWindow _sendTouchesForEvent:] + 319
28  UIKit                           0x3292a319 -[UIWindow sendEvent:] + 381
29  UIKit                           0x32910695 -[UIApplication sendEvent:] + 357
30  UIKit                           0x3290ff3b _UIApplicationHandleEvent + 5827
31  GraphicsServices                0x3702322b PurpleEventCallback + 883
32  CoreFoundation                  0x30cdc523 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 39
33  CoreFoundation                  0x30cdc4c5 __CFRunLoopDoSource1 + 141
34  CoreFoundation                  0x30cdb313 __CFRunLoopRun + 1371
35  CoreFoundation                  0x30c5e4a5 CFRunLoopRunSpecific + 301
36  CoreFoundation                  0x30c5e36d CFRunLoopRunInMode + 105
37  GraphicsServices                0x37022439 GSEventRunModal + 137
38  UIKit                           0x3293ecd5 UIApplicationMain + 1081
39  SunGroupWP                      0x00002afb main (main.m:13)
40  SunGroupWP                      0x00002a80 0x1000 + 6784


Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x360eb32c __pthread_kill + 8
1   libsystem_c.dylib               0x33d8b208 pthread_kill + 48
2   libsystem_c.dylib               0x33d84298 abort + 88
3   libc++abi.dylib                 0x30720f64 abort_message + 40
4   libc++abi.dylib                 0x3071e346 _ZL17default_terminatev + 18
5   libobjc.A.dylib                 0x362a5350 _objc_terminate + 140
6   libc++abi.dylib                 0x3071e3be _ZL19safe_handler_callerPFvvE + 70
7   libc++abi.dylib                 0x3071e44a std::terminate() + 14
8   libc++abi.dylib                 0x3071f81e __cxa_rethrow + 82
9   libobjc.A.dylib                 0x362a52a2 objc_exception_rethrow + 6
10  CoreFoundation                  0x30c5e506 CFRunLoopRunSpecific + 398
11  CoreFoundation                  0x30c5e366 CFRunLoopRunInMode + 98
12  GraphicsServices                0x37022432 GSEventRunModal + 130
13  UIKit                           0x3293ecce UIApplicationMain + 1074
14  SunGroupWP                      0x00002af4 main (main.m:13)
15  SunGroupWP                      0x00002a78 0x1000 + 6776

Thread 1 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0   libsystem_kernel.dylib          0x360db3a8 kevent + 24
1   libdispatch.dylib               0x3574df04 _dispatch_mgr_invoke + 708
2   libdispatch.dylib               0x3574dc22 _dispatch_mgr_thread + 30

Thread 2 name:  WebThread
Thread 2:
0   libsystem_kernel.dylib          0x360eb0d8 __psynch_mutexwait + 24
1   libsystem_c.dylib               0x33d40674 pthread_mutex_lock + 376
2   WebCore                         0x365d84e8 _ZL17_WebTryThreadLockb + 208
3   WebCore                         0x365d87ec _ZL14WebRunLoopLockP19__CFRunLoopObservermPv + 24
4   CoreFoundation                  0x30cdcb14 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 12
5   CoreFoundation                  0x30cdad50 __CFRunLoopDoObservers + 252
6   CoreFoundation                  0x30cdb16a __CFRunLoopRun + 946
7   CoreFoundation                  0x30c5e49e CFRunLoopRunSpecific + 294
8   CoreFoundation                  0x30c5e366 CFRunLoopRunInMode + 98
9   WebCore                         0x3667bc9c _ZL12RunWebThreadPv + 396
10  libsystem_c.dylib               0x33d4c72e _pthread_start + 314
11  libsystem_c.dylib               0x33d4c5e8 thread_start + 0

Thread 3 name:  com.apple.NSURLConnectionLoader
Thread 3:
0   libsystem_kernel.dylib          0x360db004 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x360db1fa mach_msg + 50
2   CoreFoundation                  0x30cdc3ec __CFRunLoopServiceMachPort + 120
3   CoreFoundation                  0x30cdb124 __CFRunLoopRun + 876
4   CoreFoundation                  0x30c5e49e CFRunLoopRunSpecific + 294
5   CoreFoundation                  0x30c5e366 CFRunLoopRunInMode + 98
6   Foundation                      0x35b95bb2 +[NSURLConnection(Loader) _resourceLoadLoop:] + 302
7   Foundation                      0x35b95a7a -[NSThread main] + 66
8   Foundation                      0x35c2958a __NSThread__main__ + 1042
9   libsystem_c.dylib               0x33d4c72e _pthread_start + 314
10  libsystem_c.dylib               0x33d4c5e8 thread_start + 0

Thread 4:
0   libsystem_kernel.dylib          0x360ebcd4 __workq_kernreturn + 8
1   libsystem_c.dylib               0x33d46f36 _pthread_wqthread + 610
2   libsystem_c.dylib               0x33d46cc8 start_wqthread + 0

Thread 0 crashed with ARM Thread State:
    r0: 0x00000000    r1: 0x00000000      r2: 0x00000001      r3: 0x00000000
    r4: 0x00000006    r5: 0x3ef79d98      r6: 0x00000002      r7: 0x2fdffa70
    r8: 0x00000000    r9: 0x00000000     r10: 0x00189a70     r11: 0x3f82a0f0
    ip: 0x00000148    sp: 0x2fdffa64      lr: 0x33d8b20f      pc: 0x360eb32c
  cpsr: 0x000f0010

Binary Images:
    0x1000 -    0x3dfff +SunGroupWP armv7  <659b6f9f2db23dd8bf689984c930f57f> /var/mobile/Applications/F07B0EFA-0A65-4C63-A7EA-AB0D772CECD1/SunGroupWP.app/SunGroupWP
0x2fee9000 - 0x2ff0afff  dyld armv7  <77eddfd654df393ba9c95ff01715fd08> /usr/lib/dyld
0x30644000 - 0x30683fff  QuickLook armv7  <802b1092542a3017a0380632502610d4> /System/Library/Frameworks/QuickLook.framework/QuickLook
0x3068a000 - 0x306d6fff  CoreTelephony armv7  <b8f80d5d594c31d2b5d8fba9fdedb7e1> /System/Library/Frameworks/CoreTelephony.framework/CoreTelephony

请帮助我..提前谢谢。

【问题讨论】:

【参考方案1】:

崩溃表明从 XIB 加载 WebView 时出现问题。您能否右键单击 XIB 中的 WebView 并验证连接?如果这没有帮助,您可以删除并重新添加 WebView 吗?

【讨论】:

相反,XIB 设置完成并调用 loadView。 UINib instantiateWithOwner:options: 和上面堆栈的其余部分向我表明,视图是从此处的 XIB 加载的。 From (developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/…) "如果视图控制器有关联的 nib 文件,这个方法从 nib 文件中加载视图。" -[UIApplication sendEvent:] 表明 XIB 工作正常,这是事件未到达正确目的地的问题。 @CodaFi,我相信这里有两个视图控制器在起作用。其中一个已加载且功能齐全,是的。但是“btnAboutClicked”会触发加载另一个,从而触发崩溃。 似是而非...我会尽快测试。【参考方案2】:

崩溃指向正在发送的无法识别的选择器。你的对象不知道如何对它做出反应。无论按钮发送的选择器是什么,目标都不会实现它。

【讨论】:

实际上它在 ipad 模拟器中工作正常,但只在设备中崩溃。 那么当你在设备上崩溃时,日志会说什么? 我在这里写的。我应该编写代码 UIViewController 吗?现在,我还没有写这个委托代码。 这不是这里的问题,但是是的。您可能应该是 webView 的代表。按钮调用的是什么方法? @Playcool 请在您的代码周围使用反引号 (`) 以使其可读。

以上是关于UIButton Clicked for Webview 加载到 ipad 后应用程序崩溃的主要内容,如果未能解决你的问题,请参考以下文章

如何更改视图中每个 UIButton 的框架

Vue 无法更改嵌套 v-for 中的属性

仅当用户点击图像视图时,才在 UIScrollView 上显示 UIButton Done for Images

UIButton 内的奇怪填充

无法将 UIButton 添加到 UIScrollView

隐藏以编程方式为标签创建的 UIButton