lib/ProMotion/table/table.rb in ProMotion-2.0.1 vs lib/ProMotion/table/table.rb in ProMotion-2.1.0.beta1
- old
+ new
@@ -60,13 +60,21 @@
def search_string
self.promotion_table_data.search_string
end
- def update_table_view_data(data)
+ def update_table_view_data(data, args = {})
self.promotion_table_data.data = data
- table_view.reloadData
+ if args[:index_paths]
+ args[:animation] ||= UITableViewRowAnimationNone
+
+ table_view.beginUpdates
+ table_view.reloadRowsAtIndexPaths(Array(args[:index_paths]), withRowAnimation: args[:animation])
+ table_view.endUpdates
+ else
+ table_view.reloadData
+ end
@table_search_display_controller.searchResultsTableView.reloadData if searching?
end
def trigger_action(action, arguments, index_path)
return PM.logger.info "Action not implemented: #{action.to_s}" unless self.respond_to?(action)
@@ -98,11 +106,11 @@
unless delete_cell == false
self.promotion_table_data.delete_cell(index_path: index_path)
deletable_index_paths << index_path
end
end
- table_view.deleteRowsAtIndexPaths(deletable_index_paths, withRowAnimation:map_row_animation_symbol(animation)) if deletable_index_paths.length > 0
+ table_view.deleteRowsAtIndexPaths(deletable_index_paths, withRowAnimation: map_row_animation_symbol(animation)) if deletable_index_paths.length > 0
end
def table_view_cell(params={})
params = index_path_to_section_index(params)
data_cell = self.promotion_table_data.cell(section: params[:section], index: params[:index])
@@ -120,26 +128,29 @@
end
table_cell.setup(data_cell, self)
table_cell
end
- def update_table_data
- self.update_table_view_data(self.table_data)
+ def update_table_data(args = {})
+ # Try and detect if the args param is a NSIndexPath or an array of them
+ args = { index_paths: args } if args.is_a?(NSIndexPath) || (args.is_a?(Array) && array_all_members_of?(args, NSIndexPath))
+
+ self.update_table_view_data(self.table_data, args)
self.promotion_table_data.search(search_string) if searching?
end
########## Cocoa touch methods #################
def numberOfSectionsInTableView(table_view)
self.promotion_table_data.sections.length
end
# Number of cells
- def tableView(table_view, numberOfRowsInSection:section)
+ def tableView(table_view, numberOfRowsInSection: section)
self.promotion_table_data.section_length(section)
end
- def tableView(table_view, titleForHeaderInSection:section)
+ def tableView(table_view, titleForHeaderInSection: section)
section = promotion_table_data.section(section)
section && section[:title]
end
# Set table_data_index if you want the right hand index column (jumplist)
@@ -147,53 +158,53 @@
return if self.promotion_table_data.filtered
return self.table_data_index if self.respond_to?(:table_data_index)
nil
end
- def tableView(table_view, cellForRowAtIndexPath:index_path)
+ def tableView(table_view, cellForRowAtIndexPath: index_path)
table_view_cell(index_path: 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[:style] if data_cell[:style]
+ 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)
+ def tableView(table_view, heightForRowAtIndexPath: index_path)
(self.promotion_table_data.cell(index_path: index_path)[:height] || table_view.rowHeight).to_f
end
- def tableView(table_view, didSelectRowAtIndexPath:index_path)
+ 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], 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)
+ data_cell = self.promotion_table_data.cell(index_path: index_path, unfiltered: true)
map_cell_editing_style(data_cell[:editing_style])
end
def tableView(table_view, commitEditingStyle: editing_style, forRowAtIndexPath: index_path)
if editing_style == UITableViewCellEditingStyleDelete
delete_row(index_path)
end
end
- def tableView(tableView, sectionForSectionIndexTitle:title, atIndex:index)
+ def tableView(tableView, sectionForSectionIndexTitle: title, atIndex: index)
return index unless ["{search}", UITableViewIndexSearch].include?(self.table_data_index[0])
if index == 0
- tableView.scrollRectToVisible(CGRectMake(0.0, 0.0, 1.0, 1.0), animated:false)
+ tableView.scrollRectToVisible(CGRectMake(0.0, 0.0, 1.0, 1.0), animated: false)
NSNotFound
else
index - 1
end
end
- def deleteRowsAtIndexPaths(index_paths, withRowAnimation:animation)
+ def deleteRowsAtIndexPaths(index_paths, withRowAnimation: animation)
PM.logger.warn "ProMotion expects you to use 'delete_cell(index_paths, animation)'' instead of 'deleteRowsAtIndexPaths(index_paths, withRowAnimation:animation)'."
delete_row(index_paths, animation)
end
# Section view methods