gpt4 book ai didi

xcode - 使用按钮时图像不显示

转载 作者:行者123 更新时间:2023-11-28 07:12:32 26 4
gpt4 key购买 nike

当我点击运行应用程序时,当我点击指定按钮时应用程序不会放置图像。 (我对 Swift 和 Xcode 比较陌生,所以请耐心等待)

我将移除 UIImageViews 并改用按钮。如果我需要更多帮助,我会通知您。谢谢。

class ViewController: UIViewController {

@IBOutlet var TicTacImg1: UIImageView!
@IBOutlet var TicTacImg2: UIImageView!
@IBOutlet var TicTacImg3: UIImageView!
@IBOutlet var TicTacImg4: UIImageView!
@IBOutlet var TicTacImg5: UIImageView!
@IBOutlet var TicTacImg6: UIImageView!
@IBOutlet var TicTacImg7: UIImageView!
@IBOutlet var TicTacImg8: UIImageView!
@IBOutlet var TicTacImg9: UIImageView!

@IBOutlet var TicTacButton1: UIButton!
@IBOutlet var TicTacButton2: UIButton!
@IBOutlet var TicTacButton3: UIButton!
@IBOutlet var TicTacButton4: UIButton!
@IBOutlet var TicTacButton5: UIButton!
@IBOutlet var TicTacButton6: UIButton!
@IBOutlet var TicTacButton7: UIButton!
@IBOutlet var TicTacButton8: UIButton!
@IBOutlet var TicTacButton9: UIButton!

@IBOutlet var ResetButton: UIButton!

@IBOutlet var UserMessage: UILabel!

var plays = Dictionary <Int, Int> ()

@IBAction func UIButtonClicked(sender:UIButton) {
UserMessage.hidden = true
if plays[sender.tag] == nil && !aiDeciding && !done {
setImageForSpot(sender.tag, player:1)
}
}

func setImageForSpot (spot:Int, player:Int) {
var playerMark = player == 1 ? "x" : "o"
plays[spot] = player
switch spot {
case 1:
TicTacImg1.image = UIImage(named: playerMark)
case 2:
TicTacImg2.image = UIImage(named: playerMark)
case 3:
TicTacImg3.image = UIImage(named: playerMark)
case 4:
TicTacImg4.image = UIImage(named: playerMark)
case 5:
TicTacImg5.image = UIImage(named: playerMark)
case 6:
TicTacImg6.image = UIImage(named: playerMark)
case 7:
TicTacImg7.image = UIImage(named: playerMark)
case 8:
TicTacImg8.image = UIImage(named: playerMark)
case 9:
TicTacImg9.image = UIImage(named: playerMark)
default:
TicTacImg5.image = UIImage(named: playerMark)
}
}

最佳答案

您的 UIButtonClicked 函数需要如下所示...

    @IBAction func UIButtonClicked(sender:UIButton) {
ticTacLabel.hidden = true
if plays[sender.tag] == nil && !aiDeciding && !done {
setImageForSpot(sender.tag, player:1)
}

希望这对您有所帮助!

关于xcode - 使用按钮时图像不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27828182/

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