我在制作简单的计数器应用程序时遇到困难。我已经把代码放了但是当我点击“运行模拟”时,它总是给出错误信息。任何人都可以帮我找到我的错误吗?谢谢。
我的代码如下:
import UIKit
class ViewController: UIViewController {
var counter: Int!
@IBOutlet weak var Display: UILabel!
func updateDisplay() {
Display.text = String(counter)
}
override func viewDidLoad() {
super.viewDidLoad()
counter = 0
updateDisplay()
// 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 PlusButton(sender: AnyObject) {
counter = counter + 1
updateDisplay()
}
@IBAction func MinusButton(sender: AnyObject) {
counter = counter - 1
updateDisplay()
}
@IBAction func ClearButton(sender: AnyObject) {
counter = 0
updateDisplay()
}
}
这是Xcode中的外观 https://www.facebook.com/photo.php?fbid=10204747519271053&set=pcb.10204747520111074&type=1&theater
这是我点击运行模拟时的错误消息 https://www.facebook.com/photo.php?fbid=10204747519351055&set=pcb.10204747520111074&type=1&theater
答案 0 :(得分:0)
你的代码工作正常,但我认为你有layOut连接的问题,所以再次检查它应该是这样的:
Display
标签:
PlusButton
:
MinusButton
:
对于ClearButton
:
检查THIS示例项目以获取更多信息。