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) }
  @events[:update_cell]=->(record, cell, index_path) { update_cell_text(record, cell, index_path)}
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

#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
  self
end

#onPrepareForReleaseObject



91
92
93
94
95
96
97
98
99
# File 'lib/tgios/ui_table_view_list_binding.rb', line 91

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, willDisplayCell: cell, forRowAtIndexPath: indexPath) ⇒ 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