2016-08-26 2 views
0

2つの異なる変数の未解決の識別子を取得しています。 viewControllerクラスの変数を定義しましたが、何らかの理由でviewDidLoad()関数に変数を追加するとエラーが発生します。助言がありますか?前もって感謝します!私はあなたの中括弧をチェックし、新しいXcodeのV8ベータで6未解決の識別子 "winnerLabel"の使用

輸入のUIKit

class ViewController: UIViewController {  
    @IBOutlet weak var playAgainButton: UIButton! 
    @IBOutlet weak var winnerLabel: UILabel! 
    @IBAction func playAgain(_ sender: AnyObject) { 
    } 
    //1 is noughts, 2 is crosses 
    var activeGame = true 
    var activePlayer = 1 
    var gameState = [0, 0, 0, 0, 0, 0, 0, 0, 0] //0 - empty, 1 - noughts, 2 - crosses 
    let winningCombination = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]] 
    @IBAction func buttonPressed(_ sender: AnyObject) { 
     let activePosition = sender.tag - 1 
     if gameState[activePosition] == 0 && activeGame { 
      gameState[activePosition] = activePlayer 
      if activePlayer == 1 { 
       sender.setImage(UIImage(named: "nought.png"), for: []) 
       print(sender.tag) 
       activePlayer = 2 
      } else { 
       sender.setImage(UIImage(named: "cross.png"), for: []) 
       print(sender.tag) 
       activePlayer = 1 
      } 
      for combination in winningCombination { 
       if gameState[combination[0]] != 0 && gameState[combination[0]] == gameState[combination[1]] && gameState[combination[1]] == gameState[combination[2]] { 
        //we have winner! 
        activeGame = false 
        print(gameState[combination[0]]) 
        if gameState[combination[0]] == 1 { 
         winnerLabel.text = "Noughts has won!"       
        } else {       
         winnerLabel.text = "Crosses has won!"       
        }      
        UIView.animate(withDuration: 1, animations: {       
         self.winnerLabel.center = CGPoint(x: self.winnerLabel.center.x + 500, y: self.winnerLabel.center.y) 
         self.playAgainButton.center = CGPoint(x: self.playAgainButton.center.x + 500, y: self.playAgainButton.center.y) 
        }) 
       }      
      } 
     } 
    } 
} 

func viewDidLoad() { 
    viewDidLoad()  
    winnerLabel.isHidden = true 
    playAgainButton.isHidden = true  
    winnerLabel.center = CGPoint(x: winnerLabel.center.x - 500, y: winnerLabel.center.y) 
    playAgainButton.center = CGPoint(x: playAgainButton.center.x - 500, y: playAgainButton.center.y) 
} 

func didReceiveMemoryWarning() { 
    didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

答えて

0

をSwift3を使用しています。 viewDidLoadの前にあまりにも多くのことがある場合は、クラスを閉じるために最後に1つ必要です。

また、viewDidLoad()didReceiveMemoryWarning()機能は、彼らの前にキーワードオーバーライドを持っている必要があります。

override func viewDidLoad() { 
+0

感謝を!うん、私はエラーを取得していたので、オーバーライドとスーパーを取り除き、それを取り除くことを提案した。しかし、私はそれらを戻しました。感謝します –

関連する問題