DropDownMenuKit icon indicating copy to clipboard operation
DropDownMenuKit copied to clipboard

Creating Sections

Open johnallen24 opened this issue 7 years ago • 1 comments

Hi

Just wondering if it is possible to create sections with section headers like in a UITableView?

Thanks

johnallen24 avatar May 22 '18 18:05 johnallen24

Hi,

Sorry for the very late reply. It won't work out of the box, since DropDownMenu.menuCells is a flat array.

To work around this, you can probably do something along these lines:

  • subclass DropDownMenu
  • add variable menuCellsBySection that gets updated every time menuCells is updated
  • override the following UITableViewDataSource/Delegate methods to use menuCellsBySection
    • numberOfSections(in:)
    • tableView(_:, numberOfRowsInSection:)
    • tableView(_:, heightForRowAt:)
    • tableView(_:, cellForRowAt:)
    • `tableView(_:, shouldHighlightRowAt:)``
    • tableView(_:, didSelectRowAt:)
  • override selectMenuCell(_:) to take in account the section

It's probably not exactly easy to do, but if you take a look at the source code, it should be doable.

In the long run, DropDownMenuKit could support sections out of the box or I might tweak the API to simplify the workaround above.

qmathe avatar Oct 12 '18 15:10 qmathe