UIMenu initial taping not working

I using UIMenu() for the dropdown concept, so I want when I press uimenu button list some details but when I press the button not work initial touch, then when i touch the second time it's working. how to solve this kindly let me know

@IBOutlet weak var tapButton: UIButton!

@objc func tapButtonAction() {

        let action = UIAction(title: "Action") { _ in    }

        let menu = UIMenu(title: "Tap", options: .displayInline, children: [action])

        tapButton.showsMenuAsPrimaryAction = true

        tapButton.menu = menu

    }

Answered by Frameworks Engineer in 705805022

You appear to be adding the menu to the button in response to the button being pressed (the code is being run in a function called tapButtonAction()). So the first tap adds the menu to the button, then subsequent taps will show the menu.

You should instead move this code to a place such as viewDidLoad(), so the menu gets set before the first button tap.

Accepted Answer

You appear to be adding the menu to the button in response to the button being pressed (the code is being run in a function called tapButtonAction()). So the first tap adds the menu to the button, then subsequent taps will show the menu.

You should instead move this code to a place such as viewDidLoad(), so the menu gets set before the first button tap.

UIMenu initial taping not working
 
 
Q