ios - 按下按钮时出现 Xcode 奇怪错误

标签 ios swift unrecognized-selector

所以我的 Swift 程序在 Xcode 6.4 中运行良好,直到我特别点击了我的某个按钮。当我点击它时,模拟器崩溃并且以下内容打印到控制台:

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 = ""
}

它指的是什么异常?代码非常简单,我不确定哪里出了问题。非常感谢任何见解!

最佳答案

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

  1. 检查所有网点 (IB)
  2. 检查所有操作 (IB)

关于ios - 按下按钮时出现 Xcode 奇怪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31978240/

相关文章:

ios - 使用 phonegap(ios) 调用网络服务

ios - AVAudioSession 重新激活问题

ios - 从父类(super class) UIView 连接的 IBoutlet 仍然为零

html - 如何在 swift 中从 html 字符串转换 NSAttributedString?

ios - 从我的字典中获取图像导致 "unrecognized selector"错误

ios - 在 SwiftUI 中按下按钮时如何检测并采取措施

ios - 滚动时 UIScrollView 对齐位置

uitableview - 使用多个 NSFetchedResultsController 插入行

cocoa - 取消按钮的选择器与其他按钮的选择器的工作方式不同

ios - swift 中的 "terminating with uncaught exception of type NSException"