gpt4 book ai didi

Swift UISegmentedControl IBAction 值不改变

转载 作者:可可西里 更新时间:2023-11-01 00:38:10 24 4
gpt4 key购买 nike

所以我想跟踪用户想要循环的方向。因此我有一个分段控件来选择方向。

代码如下:

@IBOutlet weak var cycleSwitch: UISegmentedControl!
@IBAction func setCycleDirection(sender: AnyObject) {

switch cycleSwitch.selectedSegmentIndex
{
case 0:
cycleDirection = cycleSwitch.selectedSegmentIndex
case 1:
cycleDirection = cycleSwitch.selectedSegmentIndex
default:
break
}
println(cycleDirection)
}

但是什么也没有打印出来。即使我将所有内容注释掉并且只有一个 println("Im in the action") 也不会记录。我也试过这个好像语句,例如cycleSwitch.selectedSegmentIndex == 0 等。均无效。

关于为什么值不会改变的任何建议或想法?

最佳答案

需要检查的几件事:

  1. 确保您的分段控件通过其“Value Changed”操作连接到 @IBAction。为此,请在您的 Storyboard 中控制并单击您的分段控件,然后仔细检查以确保“Value Changed”连接到您的 View Controller
  2. sender: 参数更改为 UISegmentedControl 而不是 AnyObject
  3. 不是引用你的 cycleSwitch @IBOutlet,而是在你的 switch 语句中引用 sender:
switch sender.selectedSegmentIndex
{
case 0:
cycleDirection = sender.selectedSegmentIndex
case 1:
cycleDirection = sender.selectedSegmentIndex
default:
break
}

关于Swift UISegmentedControl IBAction 值不改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26126767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com