2016-08-26 2 views
0

두 개의 다른 변수에 대해 확인되지 않은 식별자가 나타납니다. viewController 클래스에서 변수를 정의했지만 viewDidLoad() 함수에 변수를 추가 할 때 오류가 발생합니다. 어떤 제안? 미리 감사드립니다! 나는 당신의 중괄호를 확인 새로운 엑스 코드 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 전에 너무 많은 것을 가지고 있다면 수업을 끝내려면 맨 끝에 하나씩 필요합니다.

는 또한, viewDidLoad()didReceiveMemoryWarning() 기능이 그들 앞에 키워드 재정이 있어야합니다

override func viewDidLoad() { 
+0

감사합니다! 그래, 내가 오버라이드와 슈퍼를 빼앗 겼어. 내가 실수를해서 그걸 가져 가라고 제안 했거든. 하지만 나는 그들을 다시 추가했다. 고맙다. –

관련 문제