lib/ProMotion/helpers/motion-table/1st/sectioned_table.rb in ProMotion-0.1.2 vs lib/ProMotion/helpers/motion-table/1st/sectioned_table.rb in ProMotion-0.2.0

- old
+ new

@@ -7,34 +7,39 @@ return tableView end def updateTableViewData(data) setTableViewData data - @tableView.reloadData + self.tableView.reloadData end def setTableViewData(data) @mt_table_view_groups = data end def numberOfSectionsInTableView(tableView) - return @mt_table_view_groups.length if @mt_table_view_groups + if @mt_filtered + return @mt_filtered_data.length if @mt_filtered_data + else + return @mt_table_view_groups.length if @mt_table_view_groups + end 0 end # Number of cells def tableView(tableView, numberOfRowsInSection:section) - return sectionAtIndex(section)[:cells].length + return sectionAtIndex(section)[:cells].length if sectionAtIndex(section) + 0 end def tableView(tableView, titleForHeaderInSection:section) - return sectionAtIndex(section)[:title] + return sectionAtIndex(section)[:title] if sectionAtIndex(section) end # Set table_data_index if you want the right hand index column (jumplist) def sectionIndexTitlesForTableView(tableView) - self.table_data_index if respond_to? :table_data_index + self.table_data_index if respond_to?(:table_data_index) end def tableView(tableView, cellForRowAtIndexPath:indexPath) dataCell = cellAtSectionAndIndex(indexPath.section, indexPath.row) dataCell[:cellStyle] ||= UITableViewCellStyleDefault @@ -57,27 +62,42 @@ if dataCell[:subtitle] tableCell.detailTextLabel.text = dataCell[:subtitle] end + tableCell.selectionStyle = UITableViewCellSelectionStyleNone if dataCell[:no_select] if dataCell[:image] tableCell.imageView.layer.masksToBounds = true tableCell.imageView.image = dataCell[:image][:image] tableCell.imageView.layer.cornerRadius = dataCell[:image][:radius] if dataCell[:image][:radius] end + if dataCell[:subViews] + dataCell[:subViews].each do |view| + tableCell.addSubview view + end + end + + if dataCell[:details] + tableCell.addSubview dataCell[:details][:image] + end + tableCell.text = dataCell[:title] return tableCell end def sectionAtIndex(index) - @mt_table_view_groups.at(index) + if @mt_filtered && tableView == self.tableView + @mt_filtered_data.at(index) + else + @mt_table_view_groups.at(index) + end end def cellAtSectionAndIndex(section, index) - return sectionAtIndex(section)[:cells].at(index) + return sectionAtIndex(section)[:cells].at(index) if sectionAtIndex(section) && sectionAtIndex(section)[:cells] end def tableView(tableView, didSelectRowAtIndexPath:indexPath) cell = cellAtSectionAndIndex(indexPath.section, indexPath.row) tableView.deselectRowAtIndexPath(indexPath, animated: true); @@ -88,21 +108,21 @@ tableCell = switch.superview indexPath = tableCell.superview.indexPathForCell(tableCell) dataCell = cellAtSectionAndIndex(indexPath.section, indexPath.row) dataCell[:arguments] = {} unless dataCell[:arguments] - dataCell[:arguments][:value] = switch.isOn + dataCell[:arguments][:value] = switch.isOn if dataCell[:arguments].is_a? Hash triggerAction(dataCell[:accessoryAction], dataCell[:arguments]) if dataCell[:accessoryAction] end def triggerAction(action, arguments) if self.respond_to?(action) expectedArguments = self.method(action).arity if expectedArguments == 0 self.send(action) - elsif expectedArguments == 1 + elsif expectedArguments == 1 || expectedArguments == -1 self.send(action, arguments) else MotionTable::Console.log("MotionTable warning: #{action} expects #{expectedArguments} arguments. Maximum number of required arguments for an action is 1.", withColor: MotionTable::Console::RED_COLOR) end else \ No newline at end of file