XCode7/Swift 无法识别的选择器发送到实例?

XCode7/Swift Unrecognized Selector Sent to Instance?

我正在编写一个显示 Sierpinski 三角形的应用程序,它带有一个弹出框,允许用户控制三角形中绘制的三角形的颜色和数量。尝试通过 UIButton 更改颜色时,我的应用程序崩溃并收到错误 "unrecognized selector sent to instance"。我的应用程序已设置为具有绘制三角形的 SierpinskiView、充当视图委托且主要仅嵌入滚动视图的 SierpinskiViewController 以及控制弹出窗口并充当委托的 ControlsViewController对于 SierpinskiViewController,并告诉它要告诉 SierpinskiView 绘制多少个三角形以及使用什么颜色。我怀疑我的崩溃可能与错误使用委托有关。

这里是一些相关的代码:

Xcode 将此引用为导致应用程序崩溃的方法:

 @IBAction func changeColor(sender: UIButton) {
    let color = sender.currentTitle!
    switch mainColorSelected {
    case true:
        switch color {
        case "R": mainColor = UIColor.redColor()
        case "O": mainColor = UIColor.orangeColor()
        case "Y": mainColor = UIColor.yellowColor()
        case "G": mainColor = UIColor.greenColor()
        case "B": mainColor = UIColor.blueColor()
        case "P": mainColor = UIColor.purpleColor()
        case "Bl": mainColor = UIColor.blackColor()
        case "W": mainColor = UIColor.whiteColor()
        default: break
        }
    case false:
        switch color {
        case "R": backgroundColor = UIColor.redColor()
        case "O": backgroundColor = UIColor.orangeColor()
        case "Y": backgroundColor = UIColor.yellowColor()
        case "G": backgroundColor = UIColor.greenColor()
        case "B": backgroundColor = UIColor.blueColor()
        case "P": backgroundColor = UIColor.purpleColor()
        case "Bl": backgroundColor = UIColor.blackColor()
        case "W": backgroundColor = UIColor.whiteColor()
        default: break
        }
    }
}

选定的主要颜色:

  var mainColorSelected = false {
    didSet {
        switch mainColorSelected {
        case true: MainColorButton.setTitleColor(UIColor.redColor(), forState: .Normal)
            BackgroundColorButton.setTitleColor(UIColor.blueColor(), forState: .Normal)
        case false: BackgroundColorButton.setTitleColor(UIColor.redColor(), forState: .Normal)
            MainColorButton.setTitleColor(UIColor.blueColor(), forState: .Normal)
        }
    }
}

主要颜色:

var mainColor : UIColor = UIColor.whiteColor() {
    didSet {
        updateUI(sierpinskiViewController!)
    }
}

背景颜色:

 var backgroundColor: UIColor = UIColor.blackColor() {
    didSet {
        updateUI(sierpinskiViewController!)
    }
}

非常感谢您的帮助!

编辑:这是堆栈跟踪:

2015-07-16 11:51:04.059 Sierpinski Triangle[67645:3302773] - [Sierpinski_Triangle.ControlsViewController changeBackgroundColor:]: unrecognized selector sent to instance 0x7fedbb72c350
2015-07-16 11:51:04.072 Sierpinski Triangle[67645:3302773] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Sierpinski_Triangle.ControlsViewController changeBackgroundColor:]: unrecognized selector sent to instance 0x7fedbb72c350'
*** First throw call stack:
(
0   CoreFoundation                      0x00000001077c8885 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x0000000109571df1 objc_exception_throw + 48
2   CoreFoundation                      0x00000001077d0b5d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x000000010771de3a ___forwarding___ + 970
4   CoreFoundation                      0x000000010771d9e8 _CF_forwarding_prep_0 + 120
5   UIKit                               0x00000001081fe257 -[UIApplication sendAction:to:from:forEvent:] + 125
6   UIKit                               0x00000001081fe1b2 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 79
7   UIKit                               0x0000000108359422 -[UIControl sendAction:to:forEvent:] + 67
8   UIKit                               0x00000001083596c6 -[UIControl _sendActionsForEvents:withEvent:] + 272
9   UIKit                               0x00000001083588a9 -[UIControl touchesEnded:withEvent:] + 599
10  UIKit                               0x0000000108264be8 -[UIWindow _sendTouchesForEvent:] + 835
11  UIKit                               0x00000001082657d6 -[UIWindow sendEvent:] + 865
12  UIKit                               0x000000010821a705 -[UIApplication sendEvent:] + 263
13  UIKit                               0x00000001081f75df _UIApplicationHandleEventQueue + 6031
14  CoreFoundation                      0x00000001076f30f1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15  CoreFoundation                      0x00000001076e8eac __CFRunLoopDoSources0 + 556
16  CoreFoundation                      0x00000001076e8363 __CFRunLoopRun + 867
17  CoreFoundation                      0x00000001076e7d78 CFRunLoopRunSpecific + 488
18  GraphicsServices                    0x000000010c98abca GraphicsServices + 52170
19  UIKit                               0x00000001081fc79b UIApplicationMain + 171
20  Sierpinski Triangle                 0x00000001075c6fbd main + 109
21  libdyld.dylib                       0x0000000109f4aa05 libdyld.dylib + 10757
22  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

你调用了一些函数 changeBackgroundColor()。检查你是否在代码中有它。我只看到 changeColor().