使用未解析的标识符“winnerLabel”
Posted
技术标签:
【中文标题】使用未解析的标识符“winnerLabel”【英文标题】:use of unresolved identifier "winnerLabel" 【发布时间】:2016-08-26 22:50:42 【问题描述】:我得到了几个不同变量的未解析标识符。我在 viewController 类中定义了变量,但是由于某种原因,当我将它们添加到 viewDidLoad() 函数时出现错误。有什么建议么?提前致谢!我在新的 Xcode v8 beta 6 中使用 Swift3
导入 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.
【问题讨论】:
【参考方案1】:检查你的花括号。 viewDidLoad
之前你有太多了,那么你需要在最后一个来关闭课程。
另外,viewDidLoad()
和 didReceiveMemoryWarning()
函数前面应该有关键字 override:
override func viewDidLoad()
【讨论】:
谢谢!是的,我拿走了覆盖和超级,因为我遇到了一个错误,它建议把它拿走。但我把它们加回来了。欣赏它以上是关于使用未解析的标识符“winnerLabel”的主要内容,如果未能解决你的问题,请参考以下文章
使用未解析的标识符 'json' (Swift 3) (Alamofire)
出现错误:使用未解析的标识符“LinkingObjects”