我是Swift的新手,我现在想学习它,但是我面临着一个神秘的问题。如您在下图中所看到的,有一些控件已正确链接到该View Controller,并且在按下UI中的按钮后,我们在下面执行此代码,但是我总是得到EXC_BAD_INSTRUCTION。我不明白为什么!

这是来自堆栈跟踪的一些信息。

(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

编辑:

下面的堆栈跟踪
* 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,我都得到相同的结果。

最佳答案

emailToMyselfSwitch来自哪里?如果它是 IBOutlet ,则似乎您忘记了将其从IB连接到代码。如果不是这种情况,请显示更多上下文。

10-08 05:55