按下按钮后EXC_BAD_INSTRUCTION

时间:2015-02-08 17:43:53

标签: ios swift exc-bad-instruction

我是斯威夫特的新手,我当前正试图学习它,但我遇到了一个神秘的问题。正如您在下图中所看到的,有一些控件正确链接到此View Controller,在按下UI中的按钮时,我们执行下面的代码,但我总是得到EXC_BAD_INSTRUCTION。我不明白为什么!!

enter image description here

以下是堆栈跟踪的一些信息。

(lldb) thread info
thread #1: tid = 0x9319, 0x0006c5d5 App`App.AViewController.sendCommentViaEmail (self=<unavailable>)() -> () + 9349 at AViewController.swift:49, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

(lldb) frame select 1
frame #1: 0x037067cd libobjc.A.dylib`-[NSObject performSelector:withObject:withObject:] + 84
libobjc.A.dylib`-[NSObject performSelector:withObject:withObject:] + 84:
-> 0x37067cd:  addl   $0x1c, %esp
   0x37067d0:  popl   %esi
   0x37067d1:  popl   %edi
   0x37067d2:  popl   %ebx

编辑:

下面的Stacktrace

* thread #1: tid = 0x1e19, 0x0005a5d5 A`A.AViewController.sendCommentViaEmail (self=<unavailable>)() -> () + 9349 at AViewController.swift:49, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
  * frame #0: 0x0005a5d5 A`A.AViewController.sendCommentViaEmail (self=<unavailable>)() -> () + 9349 at AViewController.swift:49
    frame #1: 0x036f47cd libobjc.A.dylib`-[NSObject performSelector:withObject:withObject:] + 84
    frame #2: 0x01ea323d UIKit`-[UIApplication sendAction:to:from:forEvent:] + 99
    frame #3: 0x02213840 UIKit`-[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 139
    frame #4: 0x036f47cd libobjc.A.dylib`-[NSObject performSelector:withObject:withObject:] + 84
    frame #5: 0x01ea323d UIKit`-[UIApplication sendAction:to:from:forEvent:] + 99
    frame #6: 0x01ea31cf UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
    frame #7: 0x01fd6e86 UIKit`-[UIControl sendAction:to:forEvent:] + 69
    frame #8: 0x01fd72a3 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 598
    frame #9: 0x01fd650d UIKit`-[UIControl touchesEnded:withEvent:] + 660
    frame #10: 0x01ef360a UIKit`-[UIWindow _sendTouchesForEvent:] + 874
    frame #11: 0x01ef40e5 UIKit`-[UIWindow sendEvent:] + 791
    frame #12: 0x01eb9549 UIKit`-[UIApplication sendEvent:] + 242
    frame #13: 0x01ec937e UIKit`_UIApplicationHandleEventFromQueueEvent + 20690
    frame #14: 0x01e9db19 UIKit`_UIApplicationHandleEventQueue + 2206
    frame #15: 0x039791df CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    frame #16: 0x0396eced CoreFoundation`__CFRunLoopDoSources0 + 253
    frame #17: 0x0396e248 CoreFoundation`__CFRunLoopRun + 952
    frame #18: 0x0396dbcb CoreFoundation`CFRunLoopRunSpecific + 443
    frame #19: 0x0396d9fb CoreFoundation`CFRunLoopRunInMode + 123
    frame #20: 0x085dc24f GraphicsServices`GSEventRunModal + 192
    frame #21: 0x085dc08c GraphicsServices`GSEventRun + 104
    frame #22: 0x01ea18b6 UIKit`UIApplicationMain + 1526
    frame #23: 0x000919cc A`main(argc=1, argv=0xbffaa62c) + 76 at main.m:12
    frame #24: 0x04490ac9 libdyld.dylib`start + 1

以下是我使用的属性: 无论是否链接到UI,我都得到了相同的结果。

Properties linked to the UI controls and same result

3 个答案:

答案 0 :(得分:2)

emailToMyselfSwitch来自哪里?如果它是 IBOutlet ,您似乎忘记将它从IB连接到您的代码。如果情况并非如此,请显示更多背景信息。

答案 1 :(得分:1)

此错误EXC_BAD_INSTRUCTION通常意味着您正在调用空对象或无法响应选择器的对象(即self.null.on)或不能响应的属性上的属性或方法(选择器?)因为它被释放而被访问。

过去我遇到了这些弱势的飞行失败的麻烦。请尝试删除您房产中的weak

答案 2 :(得分:1)

你的代码是正确的。问题不在于与插座有关。我测试并打印:“价值:零” 问题出在代码的其他部分。 消息“self =”不正常。 您可以向我们展示更多信息。

enter image description here