2015-08-20 81 views
-1

我在製作簡單的計數器計數器應用程序時遇到困難。我已經把代碼,但當我點擊「運行模擬」,它總是給出錯誤信息。誰能幫我找到我的錯誤?謝謝。在iOS中製作基本的計數器計數器

我的代碼如下圖所示:

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

https://www.facebook.com/photo.php?fbid=10204747519351055&set=pcb.10204747520111074&type=1&theater它不顯示任何「!」跡象,但當我點擊「運行模擬」,它不想工作。 –

+0

任何我可以看到項目文件的地方? Github上? – Usernumbernine

回答

0

你的代碼工作時,我打運行錯誤信息模擬好,但我認爲你有layOut連接的問題,所以再次檢查它應該是這樣的:

Display標籤:

enter image description here

PlusButton

enter image description here

對於MinusButton

enter image description here

ClearButton

enter image description here

檢查更多的信息THIS樣本項目。

+0

謝謝Dharmesh!有用! –

+0

你可以接受答案.. :) –