Class: Tgios::UITableViewListBinding

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

Instance Method Summary collapse

Methods inherited from BindingBase

#dealloc, #hook, #prepareForRelease, #unhook

Constructor Details

#initializeUITableViewListBinding

Returns a new instance of UITableViewListBinding.



3
4
5
6
7
# File 'lib/tgios/ui_table_view_list_binding.rb', line 3

def initialize
  @events={}
  @events[:build_cell]=->(cell_identifier) { build_cell(cell_identifier) }.weak!
  @events[:update_cell]=->(record, cell, index_path) { update_cell_text(record, cell, index_path)}.weak!
end

Instance Method Details

#bind(tableView, list, display_field, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tgios/ui_table_view_list_binding.rb', line 9

def bind(tableView, list, display_field, options={})
  @tableView=WeakRef.new(tableView)
  @tableView.dataSource=self
  @tableView.delegate=self
  @display_field=display_field
  set_list(list)
  if @table_utility_binding.nil?
    @table_utility_binding = UITableViewUtilityBinding.new.bind(@tableView)
  else
    @table_utility_binding.bind(@tableView)
  end
  @options=(options || {})
  return self
end

#build_cell(cell_identifier) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/tgios/ui_table_view_list_binding.rb', line 41

def build_cell(cell_identifier)
  cell=UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier: cell_identifier)
  cell.textLabel.adjustsFontSizeToFitWidth = true
  if @options[:lines] && @options[:lines] != 1
    cell.textLabel.numberOfLines = 0
  end
  cell.clipsToBounds = true
  cell
end

#cell_heightObject



84
85
86
87
88
89
90
91
# File 'lib/tgios/ui_table_view_list_binding.rb', line 84

def cell_height
  return @options[:height] unless @options[:height].nil?
  if @options[:lines]
    26 + 19 * (@options[:lines] || 2)
  else
    45
  end
end

#listen_to_keyboardObject



148
149
150
# File 'lib/tgios/ui_table_view_list_binding.rb', line 148

def listen_to_keyboard
  @table_utility_binding.listen_to_keyboard
end

#on(event_name, &block) ⇒ Object



24
25
26
27
# File 'lib/tgios/ui_table_view_list_binding.rb', line 24

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

#onPrepareForReleaseObject



156
157
158
159
160
161
162
163
164
165
# File 'lib/tgios/ui_table_view_list_binding.rb', line 156

def onPrepareForRelease
  @table_utility_binding.prepareForRelease
  @events=nil
  @list=nil
  @display_field=nil
  @tableView.delegate=nil
  @tableView.dataSource=nil
  @tableView=nil

end

#reload(list) ⇒ Object



29
30
31
32
# File 'lib/tgios/ui_table_view_list_binding.rb', line 29

def reload(list)
  set_list(list)
  @tableView.reloadData()
end

#scrollViewDidEndDragging(scroll_view, willDecelerate: decelerate) ⇒ Object



144
145
146
# File 'lib/tgios/ui_table_view_list_binding.rb', line 144

def scrollViewDidEndDragging(scroll_view, willDecelerate:decelerate)
  @events[:did_end_scroll].call(scroll_view, decelerate) if @events[:did_end_scroll]
end

#scrollViewDidScroll(scroll_view) ⇒ Object



140
141
142
# File 'lib/tgios/ui_table_view_list_binding.rb', line 140

def scrollViewDidScroll(scroll_view)
  @events[:did_scroll].call(scroll_view) if @events[:did_scroll]
end

#set_list(list) ⇒ Object



34
35
36
37
38
39
# File 'lib/tgios/ui_table_view_list_binding.rb', line 34

def set_list(list)
  @list=WeakRef.new(list)
  @page = 1
  @total = nil
  @loading = nil
end

#stop_listen_to_keyboardObject



152
153
154
# File 'lib/tgios/ui_table_view_list_binding.rb', line 152

def stop_listen_to_keyboard
  @table_utility_binding.stop_listen_to_keyboard
end

#tableView(tableView, canEditRowAtIndexPath: index_path) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/tgios/ui_table_view_list_binding.rb', line 57

def tableView(tableView, cellForRowAtIndexPath: index_path)
  record = @list[index_path.row]
  cell_identifier = "CELL_IDENTIFIER"
  cell=tableView.dequeueReusableCellWithIdentifier(cell_identifier)
  cell = @events[:build_cell].call(cell_identifier) if cell.nil?
  @events[:update_cell].call(record, cell, index_path)
  cell

end

#update_cell_text(record, cell, index_path) ⇒ Object



51
52
53
54
55
# File 'lib/tgios/ui_table_view_list_binding.rb', line 51

def update_cell_text(record, cell, index_path)
  text = record.is_a?(Hash) ? record[@display_field] : record.send(@display_field)
  cell.textLabel.text=text.to_s
  cell
end