mardi 27 novembre 2018

Swift // NSPopUpButton .addingItems() problems

I searched a lot but I didn't find anything.. I'm relatively new to the programming world, and I am writing a little macOS software on Xcode. But there is the problem : I want to add items to a pop-up menu n°2 (NSPopUpButton) after clearing the menu when a specified item is selected in the pop-up n°1. So I made an outlet of both and wrote the if statements, but it doesn't work. In the app, when the first specified item is selected (because the first item is already selected when the app starts), the pop-up menu n°2 is showing what I want, but if I change the item to "item 2" (or in my case "Uncommon" instead of "Common") nothing happens. image showing "Common" selected when app starts // image showing "Uncommon" selected with same results than before I think that this is happening because the body of my first 'if' statement is executed, so the others aren't, but I don't know how to fix it. I tried to use 'switch' instead of 'if' or 'if/else if/else' statements but it doesn't work. I also tried to make a function of every if statement but then nothing happens. I hope you could help me. Thanks everyone.

    @IBOutlet weak var ingredientRarityNorthlands: NSPopUpButton!
    @IBOutlet weak var ingredientListNorthlands: NSPopUpButton!


   override func viewDidLoad() {
    super.viewDidLoad()


    if ingredientRarityNorthlands.titleOfSelectedItem == "Common" {
        ingredientListNorthlands.removeAllItems()
        ingredientListNorthlands.addItems(withTitles: ingredientListNorthlandsCommon)
    }
    if ingredientRarityNorthlands.titleOfSelectedItem == "Uncommon" {
        ingredientListNorthlands.removeAllItems()
        ingredientListNorthlands.addItems(withTitles: ingredientListNorthlandsUncommon)
    }

    if ingredientListNorthlands.titleOfSelectedItem == "Rare" {
        ingredientListNorthlands.removeAllItems()
        ingredientListNorthlands.addItems(withTitles: ingredientListNorthlandsRare)
    }
}

let ingredientListNorthlandsCommon = ["ok", "ko"]
let ingredientListNorthlandsUncommon = ["grer", "egr"]
let ingredientListNorthlandsRare = ["ok", "okk"]

Aucun commentaire:

Enregistrer un commentaire