Class: UIControl
Overview
Additions to UIControl to support jQuery-style ‘on` and `off` methods.
Instance Method Summary collapse
-
#off(*events) ⇒ Object
Removes all events that were bound with ‘on`.
-
#on(*events, &block) ⇒ Object
Add event handlers to UIControls.
-
#trigger(*events) ⇒ Object
Useful during testing, or to simulate a button press.
Instance Method Details
#off(*events) ⇒ Object
Removes all events that were bound with ‘on`. See symbol.rb for the uicontrolevent constant aliases.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ios/sugarcube-events/uicontrol.rb', line 33 def off(*events) if events.length == 0 events = sugarcube_callbacks.keys end events.each do |event| event = event.uicontrolevent if event.respond_to?(:uicontrolevent) sugarcube_callbacks(event).each do |handler| self.removeTarget(handler, action:'call:event:', forControlEvents:event) end sugarcube_callbacks.delete(event) end self end |
#on(*events, &block) ⇒ Object
Add event handlers to UIControls. See symbol.rb for the uicontrolevent constant aliases.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ios/sugarcube-events/uicontrol.rb', line 13 def on(*events, &block) handler = SugarCube::UIControlCallbackHelper.new(block) events.each do |event| event = event.uicontrolevent if event.respond_to?(:uicontrolevent) sugarcube_callbacks(event).push(handler) self.addTarget(handler, action:'call:event:', forControlEvents:event) end self end |
#trigger(*events) ⇒ Object
Useful during testing, or to simulate a button press.
55 56 57 58 59 60 61 62 |
# File 'lib/ios/sugarcube-events/uicontrol.rb', line 55 def trigger(*events) event_mask = 0 events.each do |event| event = event.uicontrolevent if event.respond_to?(:uicontrolevent) event_mask |= event end sendActionsForControlEvents(event_mask) end |