gpt4 book ai didi

iphone - 实现 UIStepper 时模糊使用 "value"

转载 作者:可可西里 更新时间:2023-11-01 00:52:56 25 4
gpt4 key购买 nike

我正在尝试实现一个将其值反射(reflect)到标签上的简单步进器。使用“Int(sender.value)”时出现错误“值(value)使用不明确”

//  ViewController.swift
// Stepper
//
// Created by Prabhu Konchada on 19/06/15.
// Copyright (c) 2015 Prabhu. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var StepperValue: UILabel!

@IBOutlet weak var OutputLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


@IBAction func StepperTap(sender: AnyObject) {

self.OutputLabel.text = String(Int(sender.value).description)
}
}

最佳答案

你可以像下面这样:

@IBOutlet var lblStep: UILabel!
@IBAction func stepPressed(sender: UIStepper) {

lblStep.text = sender.value.description

}

否则你必须将 AnyObject 转换为 UIStepper像那样

var stepControl : UIStepper = sender as! UIStepper

就像:

@IBAction func StepperTap(sender: AnyObject) {
var stepControl : UIStepper = sender as! UIStepper
self.OutputLabel.text = stepControl.value.description
}

与 6.1 版一样,您只需更改为 as with as 即可!对于 6.3.2:

import UIKit

class ViewController: UIViewController {

@IBOutlet var lblStep: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


@IBAction func stepPressed(sender: AnyObject) {

var step : UIStepper = sender as UIStepper

lblStep.text = step.value.description

}
}

关于iphone - 实现 UIStepper 时模糊使用 "value",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30950447/

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