2017-07-24 62 views
1

我是一个新手来迅速和我在一个井字游戏应用程序的工作。我试图写出你决定胜利者的部分。我告诉计算机,如果连续三个按钮有相同的x和o文本,则显示赢家在名为Winner的标签上。但是我得到一个错误:“类型'(Any) - >()'的值没有成员'currentTitle'。” 这里是我的代码:价值的类型'(任何) - >()'没有成员'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

按钮类成员?他们是UIButtons吗? – Dopapp

+0

你在'Buttonxxn'的每个声明的顶部都看不到'@ IBAction'吗? – OOPer

+0

[编辑]你的问题显示所有'ButtonX'属性的声明。 – rmaddy

回答

0

你有一个错字:

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


具体来说,在这里:

Buttonm.currentTitle 


要解决此问题,请用您想要参考的变量的正确名称替换ButtonmButtonm1?)。


Buttonm定义为:

@IBAction func Buttonm(_ sender: Any) { 

...因此你的错误。

+0

哎呀!非常感谢你。 – Will

相关问题