2014-10-01 39 views
5

這是我的代碼,非常感謝你的任何幫助!這是在Swift中用Xcode編寫的。我不斷收到,指出錯誤「連續聲明一行必須分開使用‘;’」我一直在Swift中出現這個錯誤。 「在一行上的連續聲明必須分隔';'」

 import UIKit 

class View Controller: UIViewController { 
@IBOutlet var outputLabel: UILabel! = UILabel() 

var currentCount : Int = 0 

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 addOneButton(sender: UIButton) { 

    currentCount = currentCount + 1 
    if(currentCount <= 1) { 
     outputLabel.text = "The button has been clicked 1 time!" 
    outputLabel.textColor = UIColor.purpleColor() 
    } 
    else { 
    outputLabel.text = "The button has been clicked \(currentCount) number of times." 
    outputLabel.textColor = UIColor.redColor() 


     var Hello: UILabel! { 
      if(currentCount >= 5) { 
       outputLabel.text = "Don't Forget To Give A GOOD Rating! :D" 
      outputLabel.textColor = UIColor.orangeColor() 
      } 
      else { 
       outputLabel.text = "Nothing To See Here..." 
       } 
+0

哪條線你的錯誤? – 2014-10-01 00:02:30

回答

4

看起來您在類名稱中的視圖和控制器之間有一個額外的空間,還有很多缺少的右括號。

試試這個:

import UIKit 

class ViewController: UIViewController { 
    @IBOutlet var outputLabel: UILabel! = UILabel() 

    var currentCount : Int = 0 

    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 addOneButton(sender: UIButton) { 

     currentCount = currentCount + 1 
     if(currentCount <= 1) { 
      outputLabel.text = "The button has been clicked 1 time!" 
      outputLabel.textColor = UIColor.purpleColor() 
     } 
     else { 
      outputLabel.text = "The button has been clicked \(currentCount) number of times." 
      outputLabel.textColor = UIColor.redColor() 

      var Hello: UILabel! { 
       if(currentCount >= 5) { 
        outputLabel.text = "Don't Forget To Give A GOOD Rating! :D" 
        outputLabel.textColor = UIColor.orangeColor() 
       } 
       else { 
        outputLabel.text = "Nothing To See Here..." 
       } 
       return outputLabel 
      } 
     } 
    } 
} 
+0

其實它沒有工作,在第四到最後一行發生錯誤。 – 2014-10-01 00:09:00

+0

很高興你把它整理出來。請確保接受對您有幫助的答案。真的很感激。 – 2014-10-01 00:11:11

+0

你能否再次幫我解決問題,在第四行到最後一行中寫着「在預期返回UILabel的函數中缺少返回值! – 2014-10-01 00:14:02

0
var Hello: UILabel! { 

這行看起來是錯誤的。去掉它。

編輯

也有}末失蹤。
正確縮進代碼將有助於發現這些錯誤!

編輯2

哦,我猜你的意思是class ViewController,而不是class View Controller

+0

我試圖刪除該行,它創建了更多的錯誤。此外,這是一個帶有文本標籤的標識,所以我沒有寫Xcode爲你做的那一行。感謝你的回答。 – 2014-10-01 00:07:15

+0

'var你好:UILabel的目的是什麼! {'?該代碼目前沒有任何意義。我很驚訝Xcode甚至編譯它。 – fluidsonic 2014-10-01 00:12:44

+0

當我添加一個新的標籤時,我選擇將它拖到執行程序爲它寫代碼,我相信這是你應該做的。 – 2014-10-01 00:15:42

相關問題