![](/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.