在iOS中制作基本计数计数器
我在制作简单的理货计数器应用程序时遇到困难。我已经输入了代码,但当我点击“运行模拟”时,它总是给出错误消息。有人能帮我找到我的错误吗?多谢各位 我的代码如下:在iOS中制作基本计数计数器,ios,iphone,swift,counter,Ios,Iphone,Swift,Counter,我在制作简单的理货计数器应用程序时遇到困难。我已经输入了代码,但当我点击“运行模拟”时,它总是给出错误消息。有人能帮我找到我的错误吗?多谢各位 我的代码如下: import UIKit class ViewController: UIViewController { var counter: Int! @IBOutlet weak var Display: UILabel! func updateDisplay() { Display.text =
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中的外观
这是我点击run simulation时的错误消息
您的代码工作正常,但我认为您的布局连接有问题,因此请再次检查,结果应该是这样的: 对于
显示
标签:
对于PlusButton
:
对于minus按钮
:
对于清除按钮
:
查看示例项目以了解更多信息。它给出了什么错误以及在哪一行?它没有显示任何“!”符号,但当我点击“运行模拟”时,它不想工作。有没有可以看到项目文件的地方?Github?你可以用它来分享图片:谢谢。这是应用程序外观这是错误外观