Quantcast
Viewing all articles
Browse latest Browse all 36

How to have an initial state with no option selected with UIButton (popup/pulldown button)?

I have this particular code

let genderOptions = ["Male".localized, "Female".localized]    .map { UIAction(title: $0, state: .off, handler: {_ in }) }genderButton.changesSelectionAsPrimaryAction = truegenderButton.menu = UIMenu(children: genderOptions)

Image may be NSFW.
Clik here to view.
enter image description here

I have set all the UIAction's state to .off, but still it is selecting the first item by default. Below is the Apple's documentation.

Image may be NSFW.
Clik here to view.
enter image description here

But when I print the selectedElements, it prints the following:

print(genderButton.menu?.selectedElements)

Image may be NSFW.
Clik here to view.
enter image description here
even though all the UIAction items state = .off, it prints an array with the first item as selected.

Q: How to have an initial state without any selection? Is popup button a good option to use here or should I use UITextField with UIPickerView?If anyone could give a complete solution, it would be great.


Viewing all articles
Browse latest Browse all 36

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>