我正在尝试使用Swift制作一个基本的计算器,但是我无法弄清楚如何在按下数字时将它们添加到顶部。我尝试每次按下按钮时将数字附加到字符串中,但是我得到了错误“append的使用不明确”。我的代码有什么问题导致出现这个错误,如何修复它使其正常工作?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var oneButton: UIButton!
@IBOutlet weak var textField: 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 onePressed(sender: AnyObject) {
textField.text?.append("1")
}
}