Class: MotionBindable::Strategies::UITextField
Constant Summary
MotionBindable::Strategy::WATCH_TICK
Instance Attribute Summary
#attr_name, #bound, #object
Instance Method Summary
collapse
#bind, find_by_reference, #initialize, register_strategy
Instance Method Details
#observeValueForKeyPath(_, ofObject: _, change: _, context: _) ⇒ Object
NSKeyValueObserving Protocol
40
41
42
|
# File 'lib/strategies/ui_text_field.rb', line 40
def observeValueForKeyPath(_, ofObject: _, change: _, context: _)
on_object_change
end
|
#on_bound_change(new = nil) ⇒ Object
24
25
26
|
# File 'lib/strategies/ui_text_field.rb', line 24
def on_bound_change(new = nil)
self.attribute = (new || bound.text)
end
|
#on_object_change(new = nil) ⇒ Object
28
29
30
|
# File 'lib/strategies/ui_text_field.rb', line 28
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
17
18
19
20
21
22
|
# File 'lib/strategies/ui_text_field.rb', line 14
def start_observing_object
object.addObserver(
self,
forKeyPath: @attr_name,
options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld,
context: nil
)
end
|
#unbind ⇒ Object
32
33
34
35
36
|
# File 'lib/strategies/ui_text_field.rb', line 32
def unbind
NSNotificationCenter.defaultCenter.removeObserver(@bound_observer)
object.removeObserver(self, forKeyPath: @attr_name)
super
end
|