UIButton reference from UIMenuElement

73 Views Asked by At

I have four UIButton's and each has an associated UIPopUpMenu. Each UIMenuElement has the same action and menu list across all four UIButtons's. My selector essentially does the same action, but saves the data into an Array based on which UIButton was originally selected to get to the UIMenu.

This is my action definition: @IBAction func changeName (sender: UIMenuElement) { }

If I try to use "sender: UIButton" instead, I get a fatal error. However, I can't seem to find out how to get a reference to the UIButton touched when using the "sender: UIMenuElement". I need the Tag from that button to determine where to save the information.

1

There are 1 best solutions below

0
user14337541 On

See my comment for my solution. Happy to share more details if anyone is curious. Thanks.

playerMenu.append(UIAction(title: allPlayers[i], handler: {_ in self.changeName(theTag: j)}))

Where allPlayers is my list of the player names, i is from the for..next adding each name to the menu, and j is from the for..next adding the menu to each button.