Module: MotionTable::SectionedTable

Included in:
GroupedTable, PlainTable
Defined in:
lib/motion-table/sectioned_table.rb

Instance Method Summary collapse

Instance Method Details

#accessoryToggledSwitch(switch) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/motion-table/sectioned_table.rb', line 88

def accessoryToggledSwitch(switch)
  tableCell = switch.superview
  indexPath = tableCell.superview.indexPathForCell(tableCell)

  dataCell = cellAtSectionAndIndex(indexPath.section, indexPath.row)
  dataCell[:arguments] = {} unless dataCell[:arguments]
  dataCell[:arguments][:value] = switch.isOn
  
  triggerAction(dataCell[:accessoryAction], dataCell[:arguments]) if dataCell[:accessoryAction]

end

#cellAtSectionAndIndex(section, index) ⇒ Object



78
79
80
# File 'lib/motion-table/sectioned_table.rb', line 78

def cellAtSectionAndIndex(section, index)
  return sectionAtIndex(section)[:cells].at(index)
end

#createTableViewFromData(data) ⇒ Object

Parameters:

  • Array (Array)

    of table data



6
7
8
9
# File 'lib/motion-table/sectioned_table.rb', line 6

def createTableViewFromData(data)
  setTableViewData data
  return tableView
end

#numberOfSectionsInTableView(tableView) ⇒ Object



20
21
22
23
# File 'lib/motion-table/sectioned_table.rb', line 20

def numberOfSectionsInTableView(tableView)
  return @mt_table_view_groups.length if @mt_table_view_groups
  0
end

#sectionAtIndex(index) ⇒ Object



74
75
76
# File 'lib/motion-table/sectioned_table.rb', line 74

def sectionAtIndex(index)
  @mt_table_view_groups.at(index)
end

#sectionIndexTitlesForTableView(tableView) ⇒ Object

Set table_data_index if you want the right hand index column (jumplist)



35
36
37
# File 'lib/motion-table/sectioned_table.rb', line 35

def sectionIndexTitlesForTableView(tableView)
  self.table_data_index if respond_to? :table_data_index
end

#setTableViewData(data) ⇒ Object



16
17
18
# File 'lib/motion-table/sectioned_table.rb', line 16

def setTableViewData(data)
  @mt_table_view_groups = data
end

#tableView(tableView, didSelectRowAtIndexPath: indexPath) ⇒ Object

Number of cells



26
27
28
# File 'lib/motion-table/sectioned_table.rb', line 26

def tableView(tableView, numberOfRowsInSection:section)
  return sectionAtIndex(section)[:cells].length
end

#triggerAction(action, arguments) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/motion-table/sectioned_table.rb', line 100

def triggerAction(action, arguments)
  if self.respond_to?(action)
    expectedArguments = self.method(action).arity
    if expectedArguments == 0
      self.send(action)
    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
    MotionTable::Console.log(self, actionNotImplemented: action)
  end
end

#updateTableViewData(data) ⇒ Object



11
12
13
14
# File 'lib/motion-table/sectioned_table.rb', line 11

def updateTableViewData(data)
  setTableViewData data
  @tableView.reloadData
end