【发布时间】:2016-05-18 14:20:24
【问题描述】:
我的想法是创建一种简单的方法来向按钮添加事件方法。
按照我的例子: Gist
问题是我遇到了 EXC_BAD_ACCESS 问题,可能是因为 #selector 中的执行不安全。
将是一种修复或更改以解决它的方法吗?
堆栈跟踪:
* thread #1: tid = 0x4e8e43, 0x0000000110355547 libsystem_blocks.dylib`_Block_copy_internal + 239, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
frame #0: 0x0000000110355547 libsystem_blocks.dylib`_Block_copy_internal + 239
frame #1: 0x000000010d8c326d Swift-201-Aula2-Exercicio2.1`@objc UICallbackButton.executeCallback(UIButton, callback : (button : UIButton) -> ()) -> () + 45 at ViewController.swift:0
frame #2: 0x000000010e2d4a8d UIKit`-[UIApplication sendAction:to:from:forEvent:] + 92
frame #3: 0x000000010e447e67 UIKit`-[UIControl sendAction:to:forEvent:] + 67
frame #4: 0x000000010e448143 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 327
frame #5: 0x000000010e447263 UIKit`-[UIControl touchesEnded:withEvent:] + 601
frame #6: 0x000000010e34799f UIKit`-[UIWindow _sendTouchesForEvent:] + 835
frame #7: 0x000000010e3486d4 UIKit`-[UIWindow sendEvent:] + 865
frame #8: 0x000000010e2f3dc6 UIKit`-[UIApplication sendEvent:] + 263
frame #9: 0x000000010e2cd553 UIKit`_UIApplicationHandleEventQueue + 6660
frame #10: 0x000000010d9d0301 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
frame #11: 0x000000010d9c622c CoreFoundation`__CFRunLoopDoSources0 + 556
frame #12: 0x000000010d9c56e3 CoreFoundation`__CFRunLoopRun + 867
frame #13: 0x000000010d9c50f8 CoreFoundation`CFRunLoopRunSpecific + 488
frame #14: 0x0000000112140ad2 GraphicsServices`GSEventRunModal + 161
frame #15: 0x000000010e2d2f09 UIKit`UIApplicationMain + 171
* frame #16: 0x000000010d8c42c2 Swift-201-Aula2-Exercicio2.1`main + 114 at AppDelegate.swift:12
frame #17: 0x000000011031292d libdyld.dylib`start + 1
【问题讨论】:
-
显示堆栈跟踪和它所指的代码行。
-
我用屏幕更新了问题,问题是我没有堆栈跟踪。
-
在调试控制台中输入
bt。 -
谢谢,添加了堆栈跟踪。我更新了 gist 文件中的一些类和方法名称。
标签: swift uibutton xcode7.3 swift2.2