lib/ProMotion/table/table.rb in ProMotion-2.0.0 vs lib/ProMotion/table/table.rb in ProMotion-2.0.1

- old
+ new

@@ -3,10 +3,11 @@ include ProMotion::Styling include ProMotion::Table::Searchable include ProMotion::Table::Refreshable include ProMotion::Table::Indexable include ProMotion::Table::Longpressable + include ProMotion::Table::Utils attr_reader :promotion_table_data def table_view self.view @@ -65,25 +66,28 @@ self.promotion_table_data.data = data table_view.reloadData @table_search_display_controller.searchResultsTableView.reloadData if searching? end - def trigger_action(action, arguments) + def trigger_action(action, arguments, index_path) return PM.logger.info "Action not implemented: #{action.to_s}" unless self.respond_to?(action) - return self.send(action) if self.method(action).arity == 0 - self.send(action, arguments) + + 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 accessory_toggled_switch(switch) table_cell = closest_parent(UITableViewCell, switch) index_path = closest_parent(UITableView, table_cell).indexPathForCell(table_cell) if index_path data_cell = promotion_table_data.cell(section: index_path.section, index: index_path.row) - data_cell[:accessory][:arguments] ||= {} data_cell[:accessory][:arguments][:value] = switch.isOn if data_cell[:accessory][:arguments].is_a?(Hash) - trigger_action(data_cell[:accessory][:action], data_cell[:accessory][:arguments]) if data_cell[:accessory][:action] + trigger_action(data_cell[:accessory][:action], data_cell[:accessory][:arguments], index_path) if data_cell[:accessory][:action] end end def delete_row(index_paths, animation = nil) deletable_index_paths = [] @@ -104,18 +108,10 @@ data_cell = self.promotion_table_data.cell(section: params[:section], index: params[:index]) return UITableViewCell.alloc.init unless data_cell create_table_cell(data_cell) end - def index_path_to_section_index(params) - if params[:index_path] - params[:section] = params[:index_path].section - params[:index] = params[:index_path].row - end - params - end - def create_table_cell(data_cell) table_cell = table_view.dequeueReusableCellWithIdentifier(data_cell[:cell_identifier]) || begin table_cell = data_cell[:cell_class].alloc.initWithStyle(data_cell[:cell_style], reuseIdentifier:data_cell[:cell_identifier]) table_cell.extend(PM::TableViewCellModule) unless table_cell.is_a?(PM::TableViewCellModule) table_cell.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin @@ -169,10 +165,10 @@ end def tableView(table_view, didSelectRowAtIndexPath:index_path) data_cell = self.promotion_table_data.cell(index_path: index_path) table_view.deselectRowAtIndexPath(index_path, animated: true) unless data_cell[:keep_selection] == true - trigger_action(data_cell[:action], data_cell[:arguments]) if data_cell[:action] + trigger_action(data_cell[:action], data_cell[:arguments], index_path) if data_cell[:action] end def tableView(table_view, editingStyleForRowAtIndexPath: index_path) data_cell = self.promotion_table_data.cell(index_path: index_path) map_cell_editing_style(data_cell[:editing_style])