gpt4 book ai didi

ios - Swift 出错,需要帮助 : property 'self.circle1' not initialized at super. 初始化调用

转载 作者:行者123 更新时间:2023-11-28 05:34:47 32 4
gpt4 key购买 nike

<分区>

我是编程新手,在我的 Tic-tac-toe 游戏中遇到此错误:属性 self.circle1 未在 super.init 调用时初始化。

我已经控制拖动并连接了我的 UIImage 和按钮以及所有这些,我还尝试从这些语句中取出 strong(使 socket 弱),我仍然无法运行我的应用程序。这是怎么回事?我的代码:

import UIKit

class ViewController: UIViewController {

//Initializing all imgs as variables:


@IBOutlet strong var circle1: UIImageView
@IBOutlet strong var circle2: UIImageView
@IBOutlet strong var circle3: UIImageView
@IBOutlet strong var circle4: UIImageView
@IBOutlet strong var circle5: UIImageView
@IBOutlet strong var circle6: UIImageView
@IBOutlet strong var circle7: UIImageView
@IBOutlet strong var circle8: UIImageView
@IBOutlet strong var circle9: UIImageView

@IBOutlet strong var circleBtn1: UIButton
@IBOutlet strong var circleBtn2: UIButton
@IBOutlet strong var circleBtn3: UIButton
@IBOutlet strong var circleBtn4: UIButton
@IBOutlet strong var circleBtn5: UIButton
@IBOutlet strong var circleBtn6: UIButton
@IBOutlet strong var circleBtn7: UIButton
@IBOutlet strong var circleBtn8: UIButton
@IBOutlet strong var circleBtn9: UIButton

@IBOutlet strong var resetBtn: UIButton
@IBOutlet strong var ResultsLabel: UILabel

//Creating variables:

var plays = Dictionary<Int,Int>()
var done = false
var aiDeciding = false

//Function that says what to do if a UIButton is clicked:

@IBAction func UIbuttonClicked(sender:UIButton) {
ResultsLabel.hidden = true
if !plays[sender.tag] && !aiDeciding && !done {
setImgforCircle(sender.tag, player:1)

}

//Executing these functions:

checkforWin()
aiTurn()

}

//Function that says sets an X or O in the proper circle depending on player:

func setImgforCircle(spot:Int, player:Int) {
var playerMark = player == 1 ? "x" : "o"
plays[spot] = player
switch spot {
case 1:
circle1.image = UIImage(named: playerMark)
case 2:
circle2.image = UIImage(named: playerMark)
case 3:
circle3.image = UIImage(named: playerMark)
case 4:
circle4.image = UIImage(named: playerMark)
case 5:
circle5.image = UIImage(named: playerMark)
case 6:
circle6.image = UIImage(named: playerMark)
case 7:
circle7.image = UIImage(named: playerMark)
case 8:
circle8.image = UIImage(named: playerMark)
case 9:
circle9.image = UIImage(named: playerMark)

default:
circle2.image = UIImage(named: playerMark)
}

}

//Function that sees if certain paths of circles have the same mark

func checkforWin() {
var whoWon = ["Lost":0, "Won":1]
for (key,value) in whoWon {
if ((plays[1] == value && plays[2] == value && plays[3] == value) || //across top row
(plays[4] == value && plays[5] == value && plays[6] == value) || //across middle row
(plays[7] == value && plays[8] == value && plays[9] == value) || //across bottom row
(plays[1] == value && plays[4] == value && plays[7] == value) || //down left column
(plays[2] == value && plays[5] == value && plays[8] == value) || //down middle column
(plays[3] == value && plays[6] == value && plays[9] == value) || //down right column
(plays[1] == value && plays[5] == value && plays[9] == value) || //diagonal going right
(plays[7] == value && plays[5] == value && plays[3] == value)) { //diagonal going left

ResultsLabel.hidden = false
ResultsLabel.text = "You \(key)!"
}

}

}
func aiTurn() {

}


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.
}
}

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com