gpt4 book ai didi

swift - 类型 '(Any) -> ()' 的值没有成员 'currentTitle'

转载 作者:行者123 更新时间:2023-11-28 08:05:31 25 4
gpt4 key购买 nike

我是 swift 的新手,正在开发一个井字游戏应用程序。我正在尝试编写您决定获胜者的部分。我告诉计算机,如果一行中的三个按钮具有相同的 x 和 o 文本,则在名为 Winner 的标签上显示获胜者。但我收到一条错误消息:“'(Any) -> ()' 类型的值没有成员 'currentTitle'。”这是我的代码:

//Winner X
if (Buttontl1.currentTitle == "X" && Buttontm1.currentTitle == "X" && Buttontr1.currentTitle == "X")
{
Winner.text = "Player X wins!"
}
else if Buttonml1.currentTitle == "X" && Buttonm1.currentTitle == "X" && Buttonmr1.currentTitle == "X"
{
Winner.text = "Player X wins!"
}
else if Buttonbl1.currentTitle == "X" && Buttonbm1.currentTitle == "X" && Buttonbr1.currentTitle == "X"
{
Winner.text = "Player X wins!"
}
else if Buttontl1.currentTitle == "X" && Buttonml1.currentTitle == "X" && Buttonbl1.currentTitle == "X"
{
Winner.text = "Player X wins!"
}
else if Buttontm1.currentTitle == "X" && Buttonm1.currentTitle == "X" && Buttonbm1.currentTitle == "X"
{
Winner.text = "Player X wins!"
}
else if Buttontr1.currentTitle == "X" && Buttonmr1.currentTitle == "X" && Buttonbr1.currentTitle == "X"
{
Winner.text = "Player X wins!"
}
else if Buttontl1.currentTitle == "X" && Buttonm1.currentTitle == "X" && Buttonbr1.currentTitle == "X"
{
Winner.text = "Player X wins!"
}
else if Buttontr1.currentTitle == "X" && Buttonm.currentTitle == "X" && Buttonbl1.currentTitle == "X"
{
Winner.text = "Player X wins!"
}
// Winner X

// Winner O
if Buttontl1.currentTitle == "O" && Buttontm1.currentTitle == "O" && Buttontr1.currentTitle == "O"
{
Winner.text = "Player O wins!"
}
else if Buttonml1.currentTitle == "O" && Buttonm1.currentTitle == "O" && Buttonmr1.currentTitle == "O"
{
Winner.text = "Player O wins!"
}
else if Buttonbl1.currentTitle == "O" && Buttonbm1.currentTitle == "O" && Buttonbr1.currentTitle == "O"
{
Winner.text = "Player O wins!"
}
else if Buttontl1.currentTitle == "O" && Buttonml1.currentTitle == "O" && Buttonbl1.currentTitle == "O"
{
Winner.text = "Player O wins!"
}
else if Buttontm1.currentTitle == "O" && Buttonm1.currentTitle == "O" && Buttonbm1.currentTitle == "O"
{
Winner.text = "Player O wins!"
}
else if Buttontr1.currentTitle == "O" && Buttonmr1.currentTitle == "O" && Buttonbr1.currentTitle == "O"
{
Winner.text = "Player O wins!"
}
else if Buttontl1.currentTitle == "O" && Buttonm1.currentTitle == "O" && Buttonbr1.currentTitle == "O"
{
Winner.text = "Player O wins!"
}
else if Buttontr1.currentTitle == "O" && Buttonm.currentTitle == "O" && Buttonbl1.currentTitle == "O"
{
Winner.text = "Player O wins!"
}
// Winner O

声明如下:

@IBOutlet weak var Winner: UILabel!

//Buttons
@IBAction func Buttonbr(_ sender: Any) {
}
@IBOutlet weak var Buttonbr1: UIButton!

@IBAction func Buttonbm(_ sender: Any) {
}
@IBOutlet weak var Buttonbm1: UIButton!

@IBAction func Buttonbl(_ sender: Any) {
}
@IBOutlet weak var Buttonbl1: UIButton!

@IBAction func Buttonmr(_ sender: Any) {
}
@IBOutlet weak var Buttonmr1: UIButton!

@IBAction func Buttonm(_ sender: Any) {
}
@IBOutlet weak var Buttonm1: UIButton!

@IBAction func Buttonml(_ sender: Any) {
}
@IBOutlet weak var Buttonml1: UIButton!

@IBAction func Buttontr(_ sender: Any) {
}
@IBOutlet weak var Buttontr1: UIButton!

@IBAction func Buttontm(_ sender: Any) {
}
@IBOutlet weak var Buttontm1: UIButton!

@IBAction func Buttontl(_ sender: Any) {
}
@IBOutlet weak var Buttontl1: UIButton!

最佳答案

你有一个错字:

else if Buttontr1.currentTitle == "O" && Buttonm.currentTitle == "O" && Buttonbl1.currentTitle == "O" 


具体来说,这里:

Buttonm.currentTitle


要解决此问题,请将 Buttonm 替换为您要引用的变量的正确名称(Buttonm1?)。


Buttonm 定义为:

@IBAction func Buttonm(_ sender: Any) {

...因此你的错误。

关于swift - 类型 '(Any) -> ()' 的值没有成员 'currentTitle',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45290059/

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