How to programmatically set an NSPopUp title. Swift4 OSX

110 Views Asked by At

I have an IB NSPopUpButton with a list of items and a number of NSTextFields.

The items from the popup are used to populate the text fields (ingredients) until a recipe is complete.

I would like to reset the popup title after each item is used but cannot find the code and syntax to do this.

I'd also like to be able to click on any of the text fields after selecting an ingredient to drop it there. Drag and drop from the popup would be ideal but I cannot find a simple way to do either so am currently using another button adjacent to each text field to initiate the drop. This is neither elegant nor ideal. Hopefully someone can propose better solutions.

My code currently looks like this

var ItemLabel: String = ""

@IBAction func Ingredients(_ sender: NSPopUpButton){

    ItemLabel = sender.titleOfSelectedItem ?? "Nil"
}
@IBOutlet weak var Ingredient1: NSTextField!

@IBAction func AddIngredient1(_ sender: NSButton){ // button next to text field

    Ingredient1Label.stringValue = ItemLabel
    // Here I need to reset the popup title

}
0

There are 0 best solutions below