lib/ProMotion/table/table.rb in ProMotion-2.5.0.beta1 vs lib/ProMotion/table/table.rb in ProMotion-2.5.0

- old
+ new

@@ -133,11 +133,12 @@ def delete_row(index_paths, animation = nil) deletable_index_paths = [] Array(index_paths).each do |index_path| delete_cell = false - delete_cell = send(:on_cell_deleted, cell_at(index_path: index_path)) if self.respond_to?("on_cell_deleted:") + + delete_cell = trigger_action(:on_cell_deleted, cell_at(index_path: index_path), index_path) if respond_to?(:on_cell_deleted) unless delete_cell == false self.promotion_table_data.delete_cell(index_path: index_path) deletable_index_paths << index_path end end @@ -184,10 +185,15 @@ def tableView(_, titleForHeaderInSection: section) section = promotion_table_data.section(section) section && section[:title] end + def tableView(_, titleForFooterInSection: section) + section = promotion_table_data.section(section) + section && section[:footer] + end + # Set table_data_index if you want the right hand index column (jumplist) def sectionIndexTitlesForTableView(_) return if self.promotion_table_data.filtered return self.table_data_index if self.respond_to?(:table_data_index) nil @@ -216,37 +222,37 @@ table_view.deselectRowAtIndexPath(index_path, animated: true) unless data_cell[:keep_selection] == true trigger_action(data_cell[:action], data_cell[:arguments], index_path) if data_cell[:action] end def tableView(_, canEditRowAtIndexPath:index_path) - data_cell = cell_at(index_path: index_path, unfiltered: true) + data_cell = cell_at(index_path: index_path, unfiltered: !searching?) [:insert,:delete].include?(data_cell[:editing_style]) end def tableView(_, editingStyleForRowAtIndexPath: index_path) - data_cell = cell_at(index_path: index_path, unfiltered: true) + data_cell = cell_at(index_path: index_path, unfiltered: !searching?) map_cell_editing_style(data_cell[:editing_style]) end def tableView(_, commitEditingStyle: editing_style, forRowAtIndexPath: index_path) if editing_style == UITableViewCellEditingStyleDelete delete_row(index_path) end end def tableView(_, canMoveRowAtIndexPath:index_path) - data_cell = cell_at(index_path: index_path, unfiltered: true) + data_cell = cell_at(index_path: index_path, unfiltered: !searching?) if (!data_cell[:moveable].nil? || data_cell[:moveable].is_a?(Symbol)) && data_cell[:moveable] != false true else false end end def tableView(_, targetIndexPathForMoveFromRowAtIndexPath:source_index_path, toProposedIndexPath:proposed_destination_index_path) - data_cell = cell_at(index_path: source_index_path, unfiltered: true) + data_cell = cell_at(index_path: source_index_path, unfiltered: !searching?) if data_cell[:moveable] == :section && source_index_path.section != proposed_destination_index_path.section source_index_path else proposed_destination_index_path @@ -284,11 +290,11 @@ def deleteRowsAtIndexPaths(index_paths, withRowAnimation: animation) mp "ProMotion expects you to use 'delete_cell(index_paths, animation)'' instead of 'deleteRowsAtIndexPaths(index_paths, withRowAnimation:animation)'.", force_color: :yellow delete_row(index_paths, animation) end - # Section view methods + # Section header view methods def tableView(_, viewForHeaderInSection: index) section = promotion_table_data.section(index) view = section[:title_view] view = section[:title_view].new if section[:title_view].respond_to?(:new) view.on_load if view.respond_to?(:on_load) @@ -311,9 +317,45 @@ end end def tableView(_, willDisplayHeaderView:view, forSection:section) action = :will_display_header + if respond_to?(action) + case self.method(action).arity + when 0 then self.send(action) + when 2 then self.send(action, view, section) + else self.send(action, view) + end + end + end + + # Section footer view methods + def tableView(_, viewForFooterInSection: index) + section = promotion_table_data.section(index) + view = section[:footer_view] + view = section[:footer_view].new if section[:footer_view].respond_to?(:new) + view.on_load if view.respond_to?(:on_load) + view.title = section[:footer] if view.respond_to?(:title=) + view + end + + def tableView(_, heightForFooterInSection: index) + section = promotion_table_data.section(index) + if section[:footer_view] || section[:footer].to_s.length > 0 + if section[:footer_view_height] + section[:footer_view_height] + elsif (section_footer = tableView(_, viewForFooterInSection: index)) && section_footer.respond_to?(:height) + section_footer.height + else + tableView.sectionFooterHeight + end + else + 0.0 + end + end + + def tableView(_, willDisplayFooterView:view, forSection:section) + action = :will_display_footer if respond_to?(action) case self.method(action).arity when 0 then self.send(action) when 2 then self.send(action, view, section) else self.send(action, view)