![](/img/trans.png)
[英]Xcode Layout Variations Work on Simulator but Disappears on Physical Device
[英]UIButton linked with IBAction will not work in simulation on physical device nor simulator in Xcode 9.2
我添加了带Control + Drag的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
}
}
以编程方式分配动作。
yrBtnOutlet.addTarget(self, action: #selector(self. rollButtonPressed(_:)), for: .touchUpInside)
希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.