当我点击按钮时,我想要将标签增加2。
import UIKit
class ViewController: UIViewController {
var cur = 0;
@IBOutlet weak var money: UILabel!
@IBAction func pressbutton(sender: UIButton) {
cur = money.text!.toInt()!;
self.money.text = String(cur + 2);
}
}
这是我的当前代码,但我遇到了错误:
toInt() 不可用,使用 Int() 初始化器
出错的行为:
cur = money.text!.toInt()!;