错误:" UILabel没有名为' txt'的成员。"

时间:2015-06-24 10:58:15

标签: ios swift

这是我的代码:

import UIKit

class ViewController: UIViewController {

var currentValue: Int = 0
@IBOutlet weak var slider: UISlider!
@IBOutlet weak var targetLabel: UILabel!
var targetValue:Int = 0


override func viewDidLoad() {
    super.viewDidLoad()
    startNewRound()
    UpdateLabels()
    // 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.
}

func startNewRound() {
    targetValue = 1 + Int(arc4random_uniform(100))
    currentValue = 50
    slider.value = Float(currentValue)
}

@IBAction func showAlert(){

let message = "The value of the slider is: \(currentValue)" + "\nThe target value is: \(targetValue)"

let alert = UIAlertController(title: "Hello, World", message: message, preferredStyle: .Alert)

let action = UIAlertAction(title: "OK", style: .Default, handler: nil)

alert.addAction(action)

presentViewController(alert, animated:true, completion:nil)

startNewRound()

UpdateLabels()

}

@IBAction func sliderMoved(slider: UISlider){
    currentValue = lroundf(slider.value)
}

func UpdateLabels(){
    targetLabel.txt = String(targetValue)
}


}

如何解决错误" UILabel没有名为' txt'" 我正在使用XCode 6.3.1和Swift 1.2

1 个答案:

答案 0 :(得分:1)

targetLabel.text = String(targetValue)