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, :update_accessory, :get_section, :get_section_text, :get_section_footer_text, :get_rows, :get_row, :get_row_text, :get_row_detail_text, :touch_row, :delete_row, :can_delete_row, :should_indent, :editing_style, :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.
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 44 |
# File 'lib/tgios/table_section_list_binding.rb', line 9 def initialize(table_view, list, ={}) @table = WeakRef.new(table_view) @table.dataSource = self @table.delegate = self @list = list @options = ( || {}) @section_text_indicator = (@options.delete(:section_text_indicator) || :title) @section_footer_text_indicator = (@options.delete(:section_footer_text_indicator) || :footer_title) @rows_indicator = (@options.delete(:rows_indicator) || :rows) @row_text_indicator = (@options.delete(:row_text_indicator) || :title) @row_detail_indicator = (@options.delete(:row_detail_indicator) || :detail) @lines = (@options.delete(:lines) || 1) @lines = @lines == true ? 2 : @lines == false ? 1 : @lines @show_row_text = (@options.delete(:show_row_text) || true) @show_row_detail = (@options.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
102 103 104 105 106 107 108 109 110 |
# File 'lib/tgios/table_section_list_binding.rb', line 102 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
84 85 86 87 88 |
# File 'lib/tgios/table_section_list_binding.rb', line 84 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
96 97 98 99 100 |
# File 'lib/tgios/table_section_list_binding.rb', line 96 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
90 91 92 93 94 |
# File 'lib/tgios/table_section_list_binding.rb', line 90 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
78 79 80 81 82 |
# File 'lib/tgios/table_section_list_binding.rb', line 78 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
61 62 63 64 |
# File 'lib/tgios/table_section_list_binding.rb', line 61 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
72 73 74 75 76 |
# File 'lib/tgios/table_section_list_binding.rb', line 72 def (index_path, record=nil) record ||= @events[:get_section].call(index_path) text = record.is_a?(Hash) ? record[@section_footer_text_indicator] : record.respond_to?(@section_footer_text_indicator) ? record.send(@section_footer_text_indicator) : nil text.nil? ? nil : text.to_s end |
#get_section_text(index_path, record = nil) ⇒ Object
66 67 68 69 70 |
# File 'lib/tgios/table_section_list_binding.rb', line 66 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
166 167 168 |
# File 'lib/tgios/table_section_list_binding.rb', line 166 def numberOfSectionsInTableView(tableView) @list.length end |
#on(event_key, &block) ⇒ Object
50 51 52 53 54 |
# File 'lib/tgios/table_section_list_binding.rb', line 50 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
46 47 48 |
# File 'lib/tgios/table_section_list_binding.rb', line 46 def onPrepareForRelease @events = {} end |
#reload(list = nil) ⇒ Object
56 57 58 59 |
# File 'lib/tgios/table_section_list_binding.rb', line 56 def reload(list=nil) @list = list unless list.nil? @table.reloadData end |
#tableView(tableView, willDisplayCell: cell, forRowAtIndexPath: index_path) ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/tgios/table_section_list_binding.rb', line 124 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
119 120 121 122 |
# File 'lib/tgios/table_section_list_binding.rb', line 119 def update_accessory(cell, index_path, record) cell.accessoryType = (@options[:accessory] || :none).uitablecellaccessory cell.accessoryView = nil end |
#update_cell(cell, index_path, record = nil) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/tgios/table_section_list_binding.rb', line 112 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 |