根据ReactiveCocoa 4中UITextField中的字符数启用/禁用UIButton

时间:2015-12-10 12:43:18

标签: ios swift reactive-cocoa

如果enabled中至少有一个字符,我想将UIButton的{​​{1}}属性设置为true。如何在Reactive Cocoa 4中实现这一目标?

1 个答案:

答案 0 :(得分:1)

你可以这样做:

NSNotificationCenter.defaultCenter()
  .rac_notifications(UITextFieldTextDidChangeNotification, object: textField)
   .map { $0.object as! UITextField }
   .map { $0.text }
   .map { $0.isEmpty }
   .startWithNext { button.enabled = !$0 }