Class: MotionBindable::Strategies::UITextField
Instance Attribute Summary
#attr_name, #bound, #object
Instance Method Summary
collapse
#observeValueForKeyPath, #observe_object, #stop_observe_object
#bind, #bound_value, find_by_reference, #initialize, #object_value, register_strategy
Instance Method Details
#on_bound_change(new = nil) ⇒ Object
18
19
20
|
# File 'lib/strategies/ui_text_field.rb', line 18
def on_bound_change(new = nil)
self.attribute = (new || bound.text)
end
|
#on_object_change(new = nil) ⇒ Object
22
23
24
|
# File 'lib/strategies/ui_text_field.rb', line 22
def on_object_change(new = nil)
@bound.text = (new || attribute)
end
|
#start_observing_bound ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/strategies/ui_text_field.rb', line 5
def start_observing_bound
@bound_observer = NSNotificationCenter.defaultCenter.addObserverForName(
UITextFieldTextDidChangeNotification,
object: bound,
queue: nil,
usingBlock: proc { |_| on_bound_change }
)
end
|
#start_observing_object ⇒ Object
14
15
16
|
# File 'lib/strategies/ui_text_field.rb', line 14
def start_observing_object
observe_object { |_, new| on_object_change(new) }
end
|
#unbind ⇒ Object
26
27
28
29
30
|
# File 'lib/strategies/ui_text_field.rb', line 26
def unbind
NSNotificationCenter.defaultCenter.removeObserver(@bound_observer)
stop_observe_object
super
end
|