按下按钮时Xcode奇怪的错误

时间:2015-08-13 01:51:25

标签: ios swift unrecognized-selector

所以我在 Xcode 6.4 中的Swift程序工作正常,直到我特别点击我的一个按钮。单击它时,模拟器崩溃,并将以下内容打印到控制台:

2015-08-12 21:41:08.323 Unit Hero 2.0[2549:99472] -[Unit_Hero_2_0.ViewController finalUnitsButton:]: unrecognized selector sent to instance 0x7faf20675d10
2015-08-12 21:41:08.326 Unit Hero 2.0[2549:99472] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Unit_Hero_2_0.ViewController finalUnitsButton:]: unrecognized selector sent to instance 0x7faf20675d10'

***首先抛出调用堆栈:

0   CoreFoundation                      0x000000010b630c65 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010d19bbb7 objc_exception_throw + 45
2   CoreFoundation                      0x000000010b6380ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x000000010b58e13c ___forwarding___ + 988
4   CoreFoundation                      0x000000010b58dcd8 _CF_forwarding_prep_0 + 120
5   UIKit                               0x000000010bed0d62 -[UIApplication sendAction:to:from:forEvent:] + 75
6   UIKit                               0x000000010bfe250a -[UIControl _sendActionsForEvents:withEvent:] + 467
7   UIKit                               0x000000010bfe18d9 -[UIControl touchesEnded:withEvent:] + 522
8   UIKit                               0x000000010bf1d958 -[UIWindow _sendTouchesForEvent:] + 735
9   UIKit                               0x000000010bf1e282 -[UIWindow sendEvent:] + 682
10  UIKit                               0x000000010bee4541 -[UIApplication sendEvent:] + 246
11  UIKit                               0x000000010bef1cdc _UIApplicationHandleEventFromQueueEvent + 18265
12  UIKit                               0x000000010becc59c _UIApplicationHandleEventQueue + 2066
13  CoreFoundation                      0x000000010b564431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14  CoreFoundation                      0x000000010b55a2fd __CFRunLoopDoSources0 + 269
15  CoreFoundation                      0x000000010b559934 __CFRunLoopRun + 868
16  CoreFoundation                      0x000000010b559366 CFRunLoopRunSpecific + 470
17  GraphicsServices                    0x000000010f604a3e GSEventRunModal + 161
18  UIKit                               0x000000010becf8c0 UIApplicationMain + 1282
19  Unit Hero 2.0                       0x000000010b4251c7 main + 135
20  libdyld.dylib                       0x000000010d8d1145 start + 1

libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) 

以下是相关按钮的代码:

@IBAction func newCalculationButton(sender: AnyObject)
{
    if (equation.count != 0) //empties arrays to prepare for a new calculation
    {
        equation.removeAll()
    }

    if (unitsOriginal.count != 0)
    {
        unitsOriginal.removeAll()
    }

    if (operations.count != 0)
    {
        operations.removeAll()
    }

    if (numerator.count != 0)
    {
        numerator.removeAll()
    }

    if (denominator.count != 0)
    {
        denominator.removeAll()
    }

    if (largestComponent.count != 0)
    {
        largestComponent.removeAll()
    }

    finalNumerator = nil
    finalDenominator = nil
    isNilNumerator = 0 //counter for number of nil items in numerator
    isNilDenominator = 0 //counter for number of nil items in denominator

    mainLabel.text = ""
}

它可以指的是什么例外?代码非常简单,我不确定会出现什么问题。非常感谢任何见解!

1 个答案:

答案 0 :(得分:3)

有时我们会复制粘贴按钮,而Xcode会保留旧的引用(操作和出口)。检查一下:

  1. 检查所有插座(IB)
  2. 检查所有操作(IB)