import UIKit
public class SelectionItem: UIView {
var radioButtonController: SSRadioButtonsController
var stepper: KWStepper!
public init(){
let gcrRadioButton = SSRadioButton(frame: CGRect(x: 0, y: 100, width: 100, height: 50))
var decrementButton = UIButton(frame: CGRect(x: 400, y: 100, width: 50, height: 50))
var incrementButton = UIButton(frame: CGRect(x: 600, y: 100, width: 50, height: 50))
var countLabel = UILabel(frame: CGRect(x:500,y:100,width:50,height:50))
decrementButton.setImage(UIImage(named: "minus@2x.png"), forState: UIControlState.Normal)
incrementButton.setImage(UIImage(named: "plus@2x.png"), forState: UIControlState.Normal)
radioButtonController = SSRadioButtonsController(buttons: gcrRadioButton)
stepper = KWStepper(decrementButton: decrementButton, incrementButton: incrementButton)
stepper.delegate = self
stepper.valueChangedCallback = { [unowned self] stepper in
countLabel.text = String(format: "%.f", stepper.value)
}
super.init(frame: CGRectZero)
self.addSubview(gcrRadioButton)
self.addSubview(decrementButton)
self.addSubview(incrementButton)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("KWStepper: NSCoding is not supported!")
}
}
问题:stepper.delegate = self发生错误。无法将SelectionItem类型的值赋给KWStepperDelegate类型。 KWStepper是一个自定义的uicontrol类。我如何在其中两个之间设置委派。
答案 0 :(得分:0)
您已将委托设置为self,但由于自写,因此不会实现委托协议。它应该是:
public class SelectionItem: UIView, KWStepperDelegate
然后您的SelectionItem必须实现委托协议。