我使用sure +拖动添加了UIButton,添加了随机数字的变量和arc4random,然后使用front函数测试我的按钮以确保它工作。但是按钮完全没有响应,并且我的代码中没有错误。
import UIKit
class ViewController: UIViewController {
var randomDiceIndex1 : Int = 0
var randomDiceIndex2 : Int = 0
@IBOutlet weak var diceImageView1: UIImageView!
@IBOutlet weak var diceImageView2: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func rollButtonPressed(_ sender: UIButton) {
randomDiceIndex1 = Int(arc4random_uniform(6))
randomDiceIndex2 = Int(arc4random_uniform(6))
print(randomDiceIndex1) //This line of code is what I used to test
}
}发布于 2018-01-10 17:37:35
以编程方式分配操作。
yrBtnOutlet.addTarget(self, action: #selector(self. rollButtonPressed(_:)), for: .touchUpInside)希望这能有所帮助。
https://stackoverflow.com/questions/48179334
复制相似问题