Swift应用开发错误-线程1信号SIGABRT

时间:2018-09-06 08:40:48

标签: ios swift xcode sigabrt

我知道这个问题以前曾被问过多次,但是使用从他们的答案中获得的所有信息,我的项目仍然崩溃!

我正在学习Apple的《每个人都可以编写代码》系列中的iBook入门,其中介绍了使用Swift进行iApp开发的应用程序开发。我正在使用第17.3章,它是“多个动作和出口”,我严格按照代码和视频 进行操作,但是,当我轻按第一个开关时,对象应该变成红色,但是没有变成红色,轻拂另外两个开关会使应用程序崩溃,错误为Thread 1: signal SIGABRT。控制台错误是这样的:

2018-09-06 18:29:35.503697+1000 ColorMix[2654:141233] -[ColorMix.ViewController greenSwitch:]: unrecognized selector sent to instance 0x7f89a4c09110
2018-09-06 18:29:35.515103+1000 ColorMix[2654:141233] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ColorMix.ViewController greenSwitch:]: unrecognized selector sent to instance 0x7f89a4c09110'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001113a81e6 __exceptionPreprocess + 294
    1   libobjc.A.dylib                     0x000000010f9ce031 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000111429784 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   UIKit                               0x0000000111d5e6db -[UIResponder doesNotRecognizeSelector:] + 295
    4   CoreFoundation                      0x000000011132a898 ___forwarding___ + 1432
    5   CoreFoundation                      0x000000011132a278 _CF_forwarding_prep_0 + 120
    6   UIKit                               0x0000000111b313e8 -[UIApplication sendAction:to:from:forEvent:] + 83
    7   UIKit                               0x0000000111cac7a4 -[UIControl sendAction:to:forEvent:] + 67
    8   UIKit                               0x0000000111cacac1 -[UIControl _sendActionsForEvents:withEvent:] + 450
    9   UIKit                               0x00000001127edea0 -[UISwitchModernVisualElement sendStateChangeActions] + 73
    10  UIKit                               0x00000001121af9d3 -[UISwitchMVEGestureTrackingSession _sendStateChangeActionsIfNecessary] + 63
    11  UIKit                               0x00000001127ee62c -[UISwitchModernVisualElement _handleLongPressWithGestureLocationInBounds:gestureState:] + 760
    12  UIKit                               0x000000011212854f -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57
    13  UIKit                               0x0000000112131324 _UIGestureRecognizerSendTargetActions + 109
    14  UIKit                               0x000000011212eb6c _UIGestureRecognizerSendActions + 307
    15  UIKit                               0x000000011212ddc0 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 859
    16  UIKit                               0x0000000112112e24 _UIGestureEnvironmentUpdate + 1329
    17  UIKit                               0x00000001121128a7 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484
    18  UIKit                               0x00000001121119a9 -[UIGestureEnvironment _updateGesturesForEvent:window:] + 281
    19  UIKit                               0x0000000111ba77ab -[UIWindow sendEvent:] + 4064
    20  UIKit                               0x0000000111b4b310 -[UIApplication sendEvent:] + 352
    21  UIKit                               0x000000011248c6af __dispatchPreprocessedEventFromEventQueue + 2796
    22  UIKit                               0x000000011248f2c4 __handleEventQueueInternal + 5949
    23  CoreFoundation                      0x000000011134abb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    24  CoreFoundation                      0x000000011132f4af __CFRunLoopDoSources0 + 271
    25  CoreFoundation                      0x000000011132ea6f __CFRunLoopRun + 1263
    26  CoreFoundation                      0x000000011132e30b CFRunLoopRunSpecific + 635
    27  GraphicsServices                    0x0000000115efea73 GSEventRunModal + 62
    28  UIKit                               0x0000000111b30057 UIApplicationMain + 159
    29  ColorMix                            0x000000010f0c2a67 main + 55
    30  libdyld.dylib                       0x00000001147ec955 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

以下是我的ViewController和Main.storyboard文件的屏幕截图:

enter image description here enter image description here

此外,在我的应用崩溃后,发生了一件奇怪的事情:在第33和48行上创建了新的出口(实心圆点),在那里与出口无关。

请让我知道是否需要更多信息/代码,我们将不胜感激!

1 个答案:

答案 0 :(得分:2)

  

[ColorMix.ViewController greenSwitch:]:无法识别的选择器已发送到实例

意味着您已经创建了一个名为greenSwitch的IBAction,然后将其删除,因此请尝试将其从IB中的交换机中删除,或者在VC中创建该动作

enter image description here