Enable/disable UIButton 根据 UITextField 中的字符数在 ReactiveCocoa 4
Enable/disable UIButton according to number of characters in UITextField in ReactiveCocoa 4
我想将 UIButton
的 enabled
属性 设置为 true
,前提是 UITextField
中至少有一个字符。如何在 Reactive Cocoa 4 中实现?
你可以这样做:
NSNotificationCenter.defaultCenter()
.rac_notifications(UITextFieldTextDidChangeNotification, object: textField)
.map { [=10=].object as! UITextField }
.map { [=10=].text }
.map { [=10=].isEmpty }
.startWithNext { button.enabled = ![=10=] }
我想将 UIButton
的 enabled
属性 设置为 true
,前提是 UITextField
中至少有一个字符。如何在 Reactive Cocoa 4 中实现?
你可以这样做:
NSNotificationCenter.defaultCenter()
.rac_notifications(UITextFieldTextDidChangeNotification, object: textField)
.map { [=10=].object as! UITextField }
.map { [=10=].text }
.map { [=10=].isEmpty }
.startWithNext { button.enabled = ![=10=] }