尝试setTarget操作时发送到实例的无法识别的选择器错误

时间:2016-08-29 14:32:27

标签: ios swift selector

我试图把一个Listener点击按钮。我已经搜索了一些类似的问题,但仍然没有消除崩溃。

我继承了UIButton,将额外的参数传递给TouchUpInside事件

 class ButtonWithRunnableContainer : UIButton{
        var runnable : Runnable!
 }

现在我以编程方式添加此按钮:

public class FloatingButtonsController : NSObject{

 init (parentView:UIView!){
        super.init()
        self.parentView = parentView
 }
//...

public func registerButton (type: Int, runnable: Runnable!){

        let button = ButtonWithRunnableContainer (frame: CGRect(rect))
        button.runnable = runnable        
        button.setImage(UIImage(named: name), forState: .Normal)
        button.addTarget(self, action: "buttonAction", forControlEvents: .TouchUpInside)
        parentView.addSubview(button)        
    }

以及崩溃的地方:

    func buttonAction(sender : ButtonWithRunnableContainer!){
        sender.runnable()
    }
}

错误是:由于未捕获的异常终止应用程序`' NSInvalidArgumentException',原因:' - [orthodoxprayernew.FloatingButtonsController buttonAction]:无法识别的选择器发送到实例0x7fee13d88a50'

0 个答案:

没有答案