I added a "Pop Up Button" from XCode Object Library, and wanted to hook it up with event handler that handles menu item selection update (for app's language selection).
The button is already created in *.xib file, and what kind of function should I create to hook up with button events?
I created a IBAction handler like this:
@IBOutlet weak var languageSettingButton: UIButton!
@IBAction func onLanguageSelected() {
// handling selection
// ...
}
But dragging the selector to this IBAction function did not work. What kind of selector function is it expecting? How do I hook it up?
My usage with two menu options regarding two app languages:
The Pop Up Button:
Update:
Followed @Charles Srstka's comment:
The IBAction func needs to have a sender param:
@IBAction func onLanguageSelected(_ sender: Any?) {
}
However the interesting thing is, we are able to hook up the entire button with the IBAction func, but not the menu item's selector, what should we do with the selector here? does it need to be hooked up with a function too?



Finally figured out the solution:
Based on Charles' comment, in view controller file, add a selection handler with sender param:
@IBAction func onSelectionUpdate(_ sender: Any?) {
}
In the pop up button's menu item's selector hook, drag it all the way to "File's owner", after dragging, a small menu will show available IBAction functions, choose the one we just created.