swift - 重置 UIStepper 的值

标签 swift uistepper

我有一堆 UIsteppers,并且有一个可以重置它们的按钮。我可以将标签设置为零,但步进器上的内部计数不会改变。我尝试执行“stepper.value”,但收到错误“UIStepper 没有成员值”

@IBAction func colorlessStepper(sender: UIStepper) {
    colorlessLabel.text = String( Int(sender.value))
}

@IBAction func WhiteStepper(sender: UIStepper) {

    BlackLabel.text = String( Int(sender.value))
}

@IBAction func BlueStepper(sender: UIStepper) {
     BlueLabel.text = String( Int(sender.value))
}

@IBAction func redStepper(sender: UIStepper) {
     RedLabel.text = String( Int(sender.value))
}

@IBAction func greenStepper(sender: UIStepper) {
     GreenLabel.text = String( Int(sender.value))
}

@IBAction func blackStepper(sender: UIStepper) {
     WhiteStepper.text = String( Int(sender.value))
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

@IBAction func resetButton(sender: AnyObject) {

    greenStepper.value = 0  //where I get the error
    BlackLabel.text = "0"
    BlueLabel.text = "0"
    RedLabel.text = "0"
    GreenLabel.text = "0"
    WhiteStepper.text = "0"
    colorlessLabel.text = "0"
}

最佳答案

您已将 greenStepper 定义为 @IBAction。

您需要将步进器连接到 @IBOutlet 才能编辑其 value 属性。

由于命名冲突,您收到了令人困惑的错误消息 - 您正在尝试编辑 @IBAction 的属性。

关于swift - 重置 UIStepper 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36654818/

相关文章:

swift - 在 Swift 中以编程方式将系统镜像设置为 ImageView

Swift 4 Firebase .childAdded 未检索最新记录

iOS UIStepper 和 NSUserDefaults - 如何一起管理它们并使用双

iOS 使用步进器控制 slider 值和文本标签值

ios - Facebook iOS SDK 4 错误信息.plist

json - 如何解决错误 : "Invalid type in JSON write (NSConcreteData)"

swift - @escaping swift 3 中的闭包函数

ios - 无法识别的选择器发送到实例(UIStepper)

ios - 如何从 UITableViewCell 内部判断其父 TableView 何时被弹出?

ios - 如何访问 Cocoa Touch 类中 UIStepper 的值