【发布时间】:2018-08-30 13:14:04
【问题描述】:
我正在编写一个游戏,我有一个分段控件供用户选择难度级别。我在案例中添加了一些简单的代码来检查索引是否更改,但似乎没有更改。代码如下:
@IBAction func chooseOnePlayerDifficulty(_ sender: UISegmentedControl) {
switch onePlayerGameType {
case .sluggish:
onePlayerGameType = typeOfGame.sluggish
print("Sluggish difficulty selected.")
case .average:
onePlayerGameType = typeOfGame.average
print("Average difficulty selected.")
case .ninja:
onePlayerGameType = typeOfGame.ninja
print("Ninja difficulty selected.")
}
}
现在,当我在模拟器中进行测试时,唯一打印到控制台的内容是“选择了平均难度”。不管我选择哪一个。为什么会发生这种情况,我该如何解决?
编辑:我通过在另一个论坛上提出这个问题找到了一个有效的答案。不过感谢您的帮助。这是对我有用的答案:Here is the link to the answer
【问题讨论】:
-
您为什么期望
onePlayerGameType的值发生变化?无论它具有什么值,您的代码都将其设置为相同的值。而且您的任何代码都不依赖于分段控件。
标签: ios swift uisegmentedcontrol