我找了很多但什么也没找到..。我对编程世界比较陌生,我正在用Xcode编写一个小的macOS软件。但问题是:当在弹出的n°1中选择指定的项时,我想在清除菜单后将项添加到弹出菜单n°2 (NSPopUpButton)中。因此,我将这两个项都做了一个出口,并编写了if语句,但它不起作用。在应用程序中,当选择第一个指定的项时(因为在应用程序启动时已经选择了第一个项),弹出菜单n°2将显示我想要的内容,但是如果我将项目更改为"item 2“(或者在我的例子中是”不常见的“而不是”公共的“),什么都不会发生。在应用程序启动时显示选定的“公共”图像 // 显示“不寻常”的图像,所选结果与以前相同 --我认为这是因为我的第一个'if‘语句的主体被执行了,所以其他语句没有执行,但是我不知道如何修复它。我尝试使用'switch‘而不是'if’或' if/else‘语句,但它不起作用。我也试着对每一个if语句做一个函数,但是没有发生任何事情。我希望你能帮我。谢谢大家。
@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 ingredientRarityNorthlands.titleOfSelectedItem == "Rare" {
ingredientListNorthlands.removeAllItems()
ingredientListNorthlands.addItems(withTitles: ingredientListNorthlandsRare)
}
}
let ingredientListNorthlandsCommon = ["ok", "ko"]
let ingredientListNorthlandsUncommon = ["grer", "egr"]
let ingredientListNorthlandsRare = ["ok", "okk"]发布于 2018-11-28 10:39:03
好的,我解决了这个问题,它就像把'if‘语句放在一个"@IBAction (_发送方: NSPopUpButton)“的正文中一样简单。昨天时间很晚,我太累了,想不出用这种方法解决问题。下面是那些遇到相同问题的人的修改代码:
@IBAction func ingredientRarityNorthlands(_ sender: NSPopUpButton) {
if ingredientRarityNorthlands.titleOfSelectedItem == "Common" {
ingredientListNorthlands.removeAllItems()
ingredientListNorthlands.addItems(withTitles: ingredientListNorthlandsCommon)
}
if ingredientRarityNorthlands.titleOfSelectedItem == "Uncommon" {
ingredientListNorthlands.removeAllItems()
ingredientListNorthlands.addItems(withTitles: ingredientListNorthlandsUncommon)
}
if ingredientRarityNorthlands.titleOfSelectedItem == "Rare" {
ingredientListNorthlands.removeAllItems()
ingredientListNorthlands.addItems(withTitles: ingredientListNorthlandsRare)
}
}https://stackoverflow.com/questions/53510206
复制相似问题