Class: Tgios::TableSectionListBinding
- Inherits:
-
BindingBase
- Object
- BindingBase
- Tgios::TableSectionListBinding
- Defined in:
- lib/tgios/table_section_list_binding.rb
Constant Summary collapse
- Events =
[:cell_identifier, :build_cell, :update_cell, :get_section, :get_section_text, :get_section_footer_text, :get_rows, :get_row, :get_row_text, :get_row_detail_text, :touch_row, :cell_height, :section_header, :section_footer, :reach_bottom, :header_height, :footer_height ]
Instance Method Summary collapse
- #build_cell(cell_identifier) ⇒ Object
- #get_row(index_path) ⇒ Object
- #get_row_detail_text(index_path, record = nil) ⇒ Object
- #get_row_text(index_path, record = nil) ⇒ Object
- #get_rows(index_path) ⇒ Object
- #get_section(index_path) ⇒ Object
- #get_section_footer_text(index_path, record = nil) ⇒ Object
- #get_section_text(index_path, record = nil) ⇒ Object
-
#initialize(table_view, list, options = {}) ⇒ TableSectionListBinding
constructor
A new instance of TableSectionListBinding.
- #numberOfSectionsInTableView(tableView) ⇒ Object
- #on(event_key, &block) ⇒ Object
- #onPrepareForRelease ⇒ Object
- #reload(list = nil) ⇒ Object
- #tableView(tableView, willDisplayCell: cell, forRowAtIndexPath: index_path) ⇒ Object
- #update_accessory(cell, index_path, record) ⇒ Object
- #update_cell(cell, index_path, record = nil) ⇒ Object
Methods inherited from BindingBase
#dealloc, #hook, #prepareForRelease, #unhook
Constructor Details
#initialize(table_view, list, options = {}) ⇒ TableSectionListBinding
Returns a new instance of TableSectionListBinding.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tgios/table_section_list_binding.rb', line 8 def initialize(table_view, list, ={}) @table = WeakRef.new(table_view) @table.dataSource = self @table.delegate = self @list = list = ( || {}) @section_text_indicator = (.delete(:section_text_indicator) || :title) = (.delete(:section_footer_text_indicator) || :footer_title) @rows_indicator = (.delete(:rows_indicator) || :rows) @row_text_indicator = (.delete(:row_text_indicator) || :title) @row_detail_indicator = (.delete(:row_detail_indicator) || :detail) @lines = (.delete(:lines) || 1) @lines = @lines == true ? 2 : @lines == false ? 1 : @lines @show_row_text = (.delete(:show_row_text) || true) @show_row_detail = (.delete(:show_row_detail) || false) @events = {} @events[:cell_identifier]=->(index_path, record) { 'CELL_IDENTIFIER' }.weak! @events[:build_cell]=->(cell_identifier, index_path, record) { build_cell(cell_identifier) }.weak! @events[:update_cell]=->(cell, index_path, record) { update_cell(cell, index_path, record)}.weak! @events[:update_accessory]=->(cell, index_path, record) { update_accessory(cell, index_path, record)}.weak! @events[:get_section]=->(index_path) { get_section(index_path) }.weak! @events[:get_section_text]=->(index_path, record) { get_section_text(index_path, record) }.weak! @events[:get_section_footer_text]=->(index_path, record) { (index_path, record) }.weak! @events[:get_rows]=->(index_path) { get_rows(index_path) }.weak! @events[:get_row]=->(index_path) { get_row(index_path) }.weak! @events[:get_row_text]=->(index_path, record) { get_row_text(index_path, record) }.weak! @events[:get_row_detail_text]=->(index_path, record) { get_row_detail_text(index_path, record) }.weak! end |
Instance Method Details
#build_cell(cell_identifier) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/tgios/table_section_list_binding.rb', line 101 def build_cell(cell_identifier) cell = UITableViewCell.value1(cell_identifier) cell.textLabel.adjustsFontSizeToFitWidth = true if @lines != 1 cell.textLabel.numberOfLines = 0 end cell.clipsToBounds = true cell end |
#get_row(index_path) ⇒ Object
83 84 85 86 87 |
# File 'lib/tgios/table_section_list_binding.rb', line 83 def get_row(index_path) rows = @events[:get_rows].call(index_path) row_idx = index_path.respondsToSelector(:row) ? index_path.row : index_path rows[row_idx] end |
#get_row_detail_text(index_path, record = nil) ⇒ Object
95 96 97 98 99 |
# File 'lib/tgios/table_section_list_binding.rb', line 95 def get_row_detail_text(index_path, record=nil) record ||= @events[:get_row].call(index_path) text = record.is_a?(Hash) ? record[@row_detail_indicator] : record.send(@row_detail_indicator) text.to_s end |
#get_row_text(index_path, record = nil) ⇒ Object
89 90 91 92 93 |
# File 'lib/tgios/table_section_list_binding.rb', line 89 def get_row_text(index_path, record=nil) record ||= @events[:get_row].call(index_path) text = record.is_a?(Hash) ? record[@row_text_indicator] : record.send(@row_text_indicator) text.to_s end |
#get_rows(index_path) ⇒ Object
77 78 79 80 81 |
# File 'lib/tgios/table_section_list_binding.rb', line 77 def get_rows(index_path) record = @events[:get_section].call(index_path) rows = record.is_a?(Hash) ? record[@rows_indicator] : record.send(@rows_indicator) rows end |
#get_section(index_path) ⇒ Object
60 61 62 63 |
# File 'lib/tgios/table_section_list_binding.rb', line 60 def get_section(index_path) section_idx = index_path.respondsToSelector(:section) ? index_path.section : index_path @list[section_idx] end |
#get_section_footer_text(index_path, record = nil) ⇒ Object
71 72 73 74 75 |
# File 'lib/tgios/table_section_list_binding.rb', line 71 def (index_path, record=nil) record ||= @events[:get_section].call(index_path) text = record.is_a?(Hash) ? record[] : record.respond_to?() ? record.send() : nil text.nil? ? nil : text.to_s end |
#get_section_text(index_path, record = nil) ⇒ Object
65 66 67 68 69 |
# File 'lib/tgios/table_section_list_binding.rb', line 65 def get_section_text(index_path, record=nil) record ||= @events[:get_section].call(index_path) text = record.is_a?(Hash) ? record[@section_text_indicator] : record.send(@section_text_indicator) text.to_s end |
#numberOfSectionsInTableView(tableView) ⇒ Object
145 146 147 |
# File 'lib/tgios/table_section_list_binding.rb', line 145 def numberOfSectionsInTableView(tableView) @list.length end |
#on(event_key, &block) ⇒ Object
49 50 51 52 53 |
# File 'lib/tgios/table_section_list_binding.rb', line 49 def on(event_key,&block) raise ArgumentError.new("Event not found, valid events are: [#{Events.join(', ')}]") unless Events.include?(event_key) @events[event_key] = block.weak! self end |
#onPrepareForRelease ⇒ Object
45 46 47 |
# File 'lib/tgios/table_section_list_binding.rb', line 45 def onPrepareForRelease @events = {} end |
#reload(list = nil) ⇒ Object
55 56 57 58 |
# File 'lib/tgios/table_section_list_binding.rb', line 55 def reload(list=nil) @list = list unless list.nil? @table.reloadData end |
#tableView(tableView, willDisplayCell: cell, forRowAtIndexPath: index_path) ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/tgios/table_section_list_binding.rb', line 123 def tableView(tableView, cellForRowAtIndexPath: index_path) record = @events[:get_row].call(index_path) cell_identifier = @events[:cell_identifier].call(index_path, record) cell=tableView.dequeueReusableCellWithIdentifier(cell_identifier) cell = @events[:build_cell].call(cell_identifier, index_path, record) if cell.nil? @events[:update_cell].call(cell, index_path, record) @events[:update_accessory].call(cell, index_path, record) cell end |
#update_accessory(cell, index_path, record) ⇒ Object
118 119 120 121 |
# File 'lib/tgios/table_section_list_binding.rb', line 118 def update_accessory(cell, index_path, record) cell.accessoryType = ([:accessory] || :none).uitablecellaccessory cell.accessoryView = nil end |
#update_cell(cell, index_path, record = nil) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/tgios/table_section_list_binding.rb', line 111 def update_cell(cell, index_path, record=nil) record ||= @events[:get_row].call(index_path) cell.textLabel.text = @events[:get_row_text].call(index_path, record) if @show_row_text cell.detailTextLabel.text = @events[:get_row_detail_text].call(index_path, record) if @show_row_detail cell.detailTextLabel end |