更改字段更改时的uiLabel值Swift(新手)

时间:2014-12-13 22:53:49

标签: swift uilabel editing

免责声明:首款iOS / Swift应用程序并遵循教程。

我正在尝试根据我在uiField中输入的内容更新uilabel的值。在调试器中,我看到它进入onEditingChanged(),但标签的值永远不会改变...没有抛出错误。此外,对tipLabel.text =“$ 0.00”和totalLabel.text =“$ 0.00”的初始分配工作正常......

有什么建议可能有问题吗?

//  ViewController.swift
//  tips
//
//  Created by Jonida Cali on 12/13/14.
//  Copyright (c) 2014 Jonida Cali. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var amountField: UITextField!
@IBOutlet weak var tipLabel: UILabel!
@IBOutlet weak var totalLabel: UILabel!


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    tipLabel.text = "$0.00"
    totalLabel.text = "$0.00"

}

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

@IBAction func onEditingChanged(sender: AnyObject) {
    println("changed")
    var billAmount = (amountField.text as NSString).doubleValue
    var tip  = billAmount*0.2
    var total = billAmount + tip


    tipLabel.text = String(format: "$%.2f", tip)
    totalLabel.text = String(format: "$%.2f",total)
}

}

0 个答案:

没有答案