私はswift3を学んでいて、tictactoeのゲームを試してみることにしました。ゲーム終了後、すべてのボタンを無効にしようとしています。私はしようとする複数のボタンを無効にする
sender.isEnabled = false
しかし、これは私にエラーが発生します。個々のボタン用のコンセントを作成し、それを1つずつ無効にする以外に、すべてのボタンを無効にする方法はありますか?以下 は、デフォルトでは、送信者のタイプとしてAnyObject
代わりのUIButton
を設定UIButton
アクションをドラッグする(私はバグを想定)何らかの理由で私のコード
@IBAction func button(_ sender: AnyObject) {
let gamePosition = sender.tag - 1
if gamePlay == true {
if gameState[gamePosition] == 0 {
if activePlayer == 1 {
sender.setImage(UIImage(named: "nought.png"), for: [])
gameState[gamePosition] = activePlayer
activePlayer = 2
} else {
sender.setImage(UIImage(named: "cross.png"), for: [])
gameState[gamePosition] = activePlayer
activePlayer = 1
}
}
}
for combination in winningCombination {
if gameState[combination[0]] != 0 && gameState[combination[0]] == gameState[combination[1]] && gameState[combination[1]] == gameState[combination[2]] {
gamePlay = false
resultLabel.isHidden = false
playAgainButton.isHidden = false
if gameState[combination[0]] == 1 {
resultLabel.text = ("noughts have won")
} else {
resultLabel.text = (" crosses won")
}
エラーとは何ですか? – shallowThought
エラーは "プロパティに割り当てることはできません: 'sender'は 'let'定数です – Harj
' sender.isEnabled = false'を使ってこれを再現することはできません。 'sender.isEnabled = false'となる。 – shallowThought