gpt4 book ai didi

ios - 如何修复 "Argument passed to call that takes no arguments"错误?

转载 作者:搜寻专家 更新时间:2023-10-30 23:15:14 24 4
gpt4 key购买 nike

我正在尝试制作一个TicTacToe 游戏。我正在尝试使用此 checkForWinner 函数,但不断出现错误。非常感谢任何帮助。

这是我的代码

class ViewController: UIViewController {    
@IBOutlet weak var CurrentLetterLabel: UILabel!
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
@IBOutlet weak var label3: UILabel!
@IBOutlet weak var label4: UILabel!
@IBOutlet weak var label5: UILabel!
@IBOutlet weak var label6: UILabel!
@IBOutlet weak var label7: UILabel!
@IBOutlet weak var label8: UILabel!
@IBOutlet weak var label9: UILabel!
@IBOutlet weak var label10: UILabel!
@IBOutlet weak var label11: UILabel!
let letter = "XOXOXOXOXO"
var moveCounter = 0
var currentLetter:Character!
var labelArray = [UILabel]()

override func viewDidLoad() {
super.viewDidLoad()

labelArray.append(label1)
labelArray.append(label2)
labelArray.append(label3)
labelArray.append(label4)
labelArray.append(label5)
labelArray.append(label6)
labelArray.append(label7)
labelArray.append(label8)
labelArray.append(label9)
labelArray.append(label10)
labelArray.append(label11)

getCharacter()

}
func getCharacter(){
let myRange = Range<String.Index>(start: letter.startIndex.advancedBy(moveCounter), end: letter.startIndex.advancedBy(moveCounter + 1))
CurrentLetterLabel.text = letter.substringWithRange(myRange)
currentLetter = Character(letter.substringWithRange(myRange))
}

func clearLabels(Action:UIAlertAction){
label1.text = ""
label2.text = ""
label3.text = ""
label4.text = ""
label5.text = ""
label6.text = ""
label7.text = ""
label9.text = ""
label10.text = ""
label11.text = ""
}
func presentWinningAlert(){
moveCounter = 0
let alert = UIAlertController(title: "", message: "byr", preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: clearLabels)
alert.addAction(okAction)
presentViewController(alert, animated: true, completion: nil)
}

@IBAction func onTapped(sender: UITapGestureRecognizer) {
print("Here")
let selectedPoint = sender.locationInView(self.view)
print(selectedPoint)
for label in labelArray{
if CGRectContainsPoint(label1.frame, selectedPoint){
label1.text = String(currentLetter)

}
if CGRectContainsPoint(label2.frame, selectedPoint){
label2.text = String(currentLetter)
}
if CGRectContainsPoint(label3.frame, selectedPoint){
label3.text = String(currentLetter)
}
if CGRectContainsPoint(label4.frame, selectedPoint){
label4.text = String(currentLetter)
}
if CGRectContainsPoint(label5.frame, selectedPoint){
label5.text = String(currentLetter)
}
if CGRectContainsPoint(label6.frame, selectedPoint){
label6.text = String(currentLetter)
}
if CGRectContainsPoint(label7.frame, selectedPoint){
label7.text = String(currentLetter)
}
if CGRectContainsPoint(label8.frame, selectedPoint){
label8.text = String(currentLetter)
}
if CGRectContainsPoint(label9.frame, selectedPoint){
label9.text = String(currentLetter)
}
if CGRectContainsPoint(label10.frame, selectedPoint){
label10.text = String(currentLetter)
}
}

moveCounter++

if moveCounter == 9{
presentWinningAlert()
}
getCharacter()
}

func checkForWinner(){
if label1.text == label2.text && label2.text == label3.text && label3.text != "" {
presentWinningAlert("\(label3.text!)")
}

else if label4.text == label5.text && label5.text == label6.text && label6.text != "" {
presentWinningAlert("\(label6.text!)")
}
else if label7.text == label8.text && label8.text == label9.text && label9.text != "" {
presentWinningAlert("\(label9.text!)")
}
else if label1.text == label4.text && label4.text == label7.text && label7.text != "" {
presentWinningAlert("\(label7.text!)")
}
else if label2.text == label5.text && label5.text == label8.text && label8.text != "" {
presentWinningAlert("\(label8.text!)")
}
else if label3.text == label6.text && label6.text == label9.text && label9.text != "" {
presentWinningAlert("\(label9.text!)")
}
else if label1.text == label5.text && label5.text == label9.text && label9.text != "" {
presentWinningAlert("\(label9.text!)")
}
else if label3.text == label5.text && label5.text == label7.text && label7.text != "" {
presentWinningAlert("\(label7.text!)")
}

if moveCounter == 9
{
presentWinningAlert("No One")
}
}
}

最佳答案

您正在调用带有字符串参数的函数,但该函数不采用字符串参数。调用应该是

presentWinningAlert()

不传递任何参数或函数应修改为

func presentWinningAlert(title: String){
moveCounter = 0
let alert = UIAlertController(title: title, message: "byr", preferredStyle: UIAlertControllerStyle.Alert)

关于ios - 如何修复 "Argument passed to call that takes no arguments"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35301738/

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