[英]How to let Eureka trigger onChange() event on my custom Row?
我編寫了一個自定義Row,Row的值是這樣的:
struct CountUnit:Equatable,InputTypeInitiable{
var totalCount:Int
var unit:String
init?(string stringValue: String) {
//...
}
static func ==(lhs: CountUnit, rhs: CountUnit) -> Bool {
//...
}
}
我要問的是:如何讓Eureka在CountUnit的任何實例值更改時調用onChange()事件?(totalCount和unit):
<<< CountUnitRow() {row in
//do some init...
}.onChange {row in
//how to let user know value was changed
}
CountUnitRow代碼是這樣,但幾乎是空的:
final class CountUnitRow: Row<CountUnitCell>,RowType{
required init(tag: String?) {
super.init(tag: tag)
cellProvider = CellProvider<CountUnitCell>(nibName: "CountUnitCell")
}
}
CountUnitCell在這里,我在CountUnitCell UI中有一個UITextField,我想利用Eureka的UITextField自動鍵盤功能,因此CountUnitCell繼承自_FieldCell:
class CountUnitCell:_FieldCell<CountUnit>,CellType{
@IBOutlet weak var countLbl:UILabel!
@IBOutlet weak var stepper:UISlider!
var count:Int = 1{
didSet{
countLbl.text = "\(count)"
row.value?.totalCount = count
}
}
@IBAction func countChanged(_ sender:UISlider){
count = Int(sender.value)
}
func updateUI(){
if let value = row.value{
stepper.value = Float(value.totalCount)
count = value.totalCount
textField.text = value.unit
}
}
override func textFieldDidEndEditing(_ textField: UITextField) {
//super.textFieldDidEndEditing(textField)
guard let text = textField.text,text.count > 0 else {return}
row.value?.unit = text
}
override open func update() {
updateUI()
}
override open func setup() {
super.setup()
height = {return UITableViewAutomaticDimension}
textField.delegate = self
updateUI()
}
override open func didSelect() {
super.didSelect()
row.deselect()
}
required public init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
我知道了!
答案非常簡單:尤里卡(Eureka)使您的Value類型成為現實,這是全自動的!!!
謝謝尤里卡!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.