繁体   English   中英

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

[英]XCode7/Swift Unrecognized Selector Sent to Instance?

我正在编写一个显示Sierpinski三角形并带有弹出窗口的应用程序,该窗口允许用户控制在三角形中绘制的三角形的颜色和数量。 当尝试通过UIButton更改颜色时,我的应用程序崩溃了,并且出现错误“无法识别的选择器发送到实例”。 我的应用程序设置为具有一个SierpinskiView(可绘制三角形),一个SierpinskiViewController(可充当视图的委托并主要嵌入到滚动视图中)和ControlsViewController(可控制弹出窗口并充当委托)并告诉它可以告诉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
        }
    }
}

mainColorSelected:

  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)
        }
    }
}

mainColor:

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

您调用一些func changeBackgroundColor() 检查代码中是否包含它。 我只看到changeColor()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM