AssistoLab / DropDown

A Material Design drop down for iOS
MIT License
2.45k stars 628 forks source link

Set Dropdown menu in every Tableview Cell action not working!!! #88

Open riazurcse opened 7 years ago

riazurcse commented 7 years ago

I have a tableview. In every cell of my tableview there is a button & every button action it must show the dropdown option menu. I tried but can't make it work. Here is my code

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell1", for: indexPath) as! ScannedResultInfoCell    
    let optionsMenu = DropDown()
    optionsMenu.tag = indexPath.row
    setupOptionsMenu(cell, menu: optionsMenu)
    cell.actionButton.addTarget(self, action: #selector(ScannedResultController.actionButtonPressed(_:withMenu:)), for: .touchUpInside)
    return cell
}

func setupOptionsMenu(_ cell: ScannedResultInfoCell, menu: DropDown) {

        menu.anchorView = cell.actionButton
        menu.width = 120
        menu.direction = .any
        menu.bottomOffset = CGPoint(x: cell.actionButton.frame.origin.x, y: cell.actionButton.frame.size.height + 5)

        menu.dataSource = [
            "Option 1",
            "Option 2"
        ]

        menu.selectionAction = { [unowned self] (index, item) in

            if index == 0 {
                print("Option 1 selected")

            }else if index == 1 {
                print("Option 2 selected")
           }
      }
 }

func actionButtonPressed(_ sender: UIButton, withMenu menu: DropDown) {
        menu.show()
        self.tableView.reloadData()
}

I want to show the specific cell dropdown menu & come up with this but can't make it work. It crashes. Please help. Thanks in advance.

riazurcse commented 7 years ago

Solved the issue by creating a list of Dropdown menu. Thanks anyways. :)

experion-tibin commented 7 years ago

could you elaborate how you solved the problem

experion-tibin commented 7 years ago

OK got it .The dropdown variable needs to be declared globally

onegaop commented 7 years ago

I have the same problem ,what can i do for this...?

Prasath25594 commented 5 years ago

Create your DropDown variable instance along with your model object. Show/Hide corresponding drop-down on button action using your Model object with indexPath.row option.