module ProMotion module ChaTable include ProMotion::Styling include ProMotion::Table::Refreshable attr_reader :promotion_table_data def table_view self.view end def table_data PM.logger.warn "@data is require" unless @data @data || [] end def screen_setup set_up_refreshable end def set_up_refreshable if self.class.respond_to?(:get_refreshable) && self.class.get_refreshable if defined?(UIRefreshControl) self.make_refreshable(self.class.get_refreshable_params) else PM.logger.warn "To use the refresh control on < iOS 6, you need to include the CocoaPod 'CKRefreshControl'." end end end def trigger_action(action, arguments, index_path) return PM.logger.info "Action not implemented: #{action.to_s}" unless self.respond_to?(action) case self.method(action).arity when 0 then self.send(action) # Just call the method when 2 then self.send(action, arguments, index_path) # Send arguments and index path else self.send(action, arguments) # Send arguments end end def update_section(index, bool=false) self.view.reloadSections(NSIndexSet.indexSetWithIndex(index), withRowAnimation:bool) end ########## Cocoa touch methods ################# def numberOfSectionsInTableView(table_view) if self.respond_to?(:section_count) section_count else 1 end end # Number of cells def tableView(table_view, numberOfRowsInSection:section) if self.respond_to?(:row_count) row_count(section) else table_data.length end end def tableView(table_view, cellForRowAtIndexPath:index_path) table_view_cell(index_path) end def tableView(table_view, willDisplayCell: table_cell, forRowAtIndexPath: index_path) # data_cell = self.promotion_table_data.cell(index_path: index_path) # set_attributes table_cell, data_cell[:properties] if data_cell[:properties] # table_cell.send(:will_display) if table_cell.respond_to?(:will_display) # table_cell.send(:restyle!) if table_cell.respond_to?(:restyle!) # Teacup compatibility end def tableView(table_view, heightForRowAtIndexPath:index_path) cell_height(index_path) end def tableView(table_view, didSelectRowAtIndexPath:index_path) cell_action(index_path) if self.respond_to?(:cell_action) end # Section view methods def tableView(table_view, viewForHeaderInSection: index) header_view(index) if self.respond_to?(:header_view) end def tableView(table_view, heightForHeaderInSection: index) if self.respond_to?(:header_height) header_height(index) else 0 end end def update_table_view self.view.reloadData end protected def map_cell_editing_style(symbol) { none: UITableViewCellEditingStyleNone, delete: UITableViewCellEditingStyleDelete, insert: UITableViewCellEditingStyleInsert }[symbol] || symbol || UITableViewCellEditingStyleNone end def map_row_animation_symbol(symbol) symbol ||= UITableViewRowAnimationAutomatic { fade: UITableViewRowAnimationFade, right: UITableViewRowAnimationRight, left: UITableViewRowAnimationLeft, top: UITableViewRowAnimationTop, bottom: UITableViewRowAnimationBottom, none: UITableViewRowAnimationNone, middle: UITableViewRowAnimationMiddle, automatic: UITableViewRowAnimationAutomatic }[symbol] || symbol || UITableViewRowAnimationAutomatic end module TableClassMethods def table_style UITableViewStylePlain end # Refreshable def refreshable(params = {}) @refreshable_params = params @refreshable = true end def get_refreshable @refreshable ||= false end def get_refreshable_params @refreshable_params ||= nil end end def self.included(base) base.extend(TableClassMethods) end end end