类型的值'(任意) - > ()'没有会员'currentTitle'

时间:2017-07-24 21:07:38

标签: swift xcode

我是swift的新手,正在开发一个tic-tac-toe应用程序。我正在尝试写下你决定获胜者的部分。我告诉计算机,如果一行中的三个按钮具有相同的x和o文本,则显示获胜者在名为Winner的标签上的人。但我得到一个错误说:“类型的值'(任意) - >()'没有成员'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!

1 个答案:

答案 0 :(得分:0)

你有一个错字:

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


具体来说,这里:

Buttonm.currentTitle


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


Buttonm定义为:

@IBAction func Buttonm(_ sender: Any) {

...因此你的错误。