I'm trying to put a Listener for click on button. I've searched for some similar issues and still didn't eliminate crash.
I inherited UIButton to pass an extra parameter to TouchUpInside event
class ButtonWithRunnableContainer : UIButton{
var runnable : Runnable!
}
Now I add this button programmatically :
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)
}
and here's where it crashes :
func buttonAction(sender : ButtonWithRunnableContainer!){
sender.runnable()
}
}
The error is : terminating app due to uncaught exception `'NSInvalidArgumentException', reason: '-[orthodoxprayernew.FloatingButtonsController buttonAction]: unrecognized selector sent to instance 0x7fee13d88a50'