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
# 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)
  @options=(options || {})
  return self
end

#build_cell(cell_identifier) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/tgios/ui_table_view_list_binding.rb', line 35

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



77
78
79
80
81
82
83
84
# File 'lib/tgios/ui_table_view_list_binding.rb', line 77

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

#on(event_name, &block) ⇒ Object



19
20
21
22
# File 'lib/tgios/ui_table_view_list_binding.rb', line 19

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

#onPrepareForReleaseObject



131
132
133
134
135
136
137
138
139
# File 'lib/tgios/ui_table_view_list_binding.rb', line 131

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

end

#reload(list) ⇒ Object



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

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

#set_list(list) ⇒ Object



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

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

#tableView(tableView, canEditRowAtIndexPath: index_path) ⇒ Object



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

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



45
46
47
48
# File 'lib/tgios/ui_table_view_list_binding.rb', line 45

def update_cell_text(record, cell, index_path)
  cell.textLabel.text=record[@display_field]
  cell
end