Class: Tgios::UIButtonBinding

Inherits:
BindingBase show all
Defined in:
lib/tgios/ui_button_binding.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BindingBase

#hook, #prepareForRelease, #unhook

Constructor Details

#initializeUIButtonBinding

Returns a new instance of UIButtonBinding.



3
4
5
# File 'lib/tgios/ui_button_binding.rb', line 3

def initialize
  @events={}
end

Class Method Details

.unbind(button) ⇒ Object



27
28
29
# File 'lib/tgios/ui_button_binding.rb', line 27

def self.unbind(button)
  button.removeTarget(nil, action: 'button_tapped', forControlEvents: UIControlEventTouchUpInside)
end

Instance Method Details

#bind(button) ⇒ Object



12
13
14
15
16
# File 'lib/tgios/ui_button_binding.rb', line 12

def bind(button)
  @button=WeakRef.new(button)
  @button.addTarget(self, action: 'button_tapped', forControlEvents: UIControlEventTouchUpInside)
  self
end

#button_tappedObject



18
19
20
21
# File 'lib/tgios/ui_button_binding.rb', line 18

def button_tapped
  ap "button_tapped"
  @events[:tapped].call unless @events[:tapped].nil?
end

#deallocObject



31
32
33
34
# File 'lib/tgios/ui_button_binding.rb', line 31

def dealloc
  @button.removeTarget(self, action: 'button_tapped', forControlEvents: UIControlEventTouchUpInside) if @button.weakref_alive?
  super
end

#on(event_name, &block) ⇒ Object



7
8
9
10
# File 'lib/tgios/ui_button_binding.rb', line 7

def on(event_name, &block)
  @events[event_name]= block.weak!
  self
end

#onPrepareForReleaseObject



23
24
25
# File 'lib/tgios/ui_button_binding.rb', line 23

def onPrepareForRelease
  @events=nil
end