Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a pull down menu with storyboard

I'm trying to use a pull down menu in my app using the storyboard but I keep getting an error saying "Menu does not have a valid element for default selection". My setup looks like this:

pull down menu with menu items

I've successfully managed to implement a pull down menu using code, following this answer: How to show pull down button menu in IOS 14 swift but I'd like to know how to do it using a storyboard.

I think I'm missing the assignment of the UIMenuElement to my button, because when I remove the assignment in code button.menu = menu it does't work either. I just can't seem to figure out how to connect the 2 using the storyboard.

like image 205
Dennis Avatar asked Oct 19 '25 15:10

Dennis


1 Answers

You have to make sure that each of your menu commands have actions associated with them; otherwise, at run time, that exception is thrown.

So, after clicking on a menu command, go to the Connections Inspector and wire up an action to your code:

enter image description here

like image 78
John Caccavale Avatar answered Oct 21 '25 08:10

John Caccavale



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!