简体   繁体   English

与IBAction链接的UIButton在物理设备上的仿真中也不起作用,在Xcode 9.2中的仿真器中也不起作用

[英]UIButton linked with IBAction will not work in simulation on physical device nor simulator in Xcode 9.2

I added the UIButton with Control + Drag, added the variables and arc4random for randomized numbers, and then used a front function to test my button to make sure it worked. 我添加了带Control + Drag的UIButton,添加了变量和arc4random以获取随机数,然后使用front函数测试我的按钮以确保其正常工作。 But the button is totally unresponsive and I have no errors in my code. 但是按钮完全没有响应,我的代码没有错误。

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
    }
}

Assign action programmatically. 以编程方式分配动作。

yrBtnOutlet.addTarget(self, action: #selector(self. rollButtonPressed(_:)), for: .touchUpInside)

Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xcode 布局变化在模拟器上工作但在物理设备上消失 - Xcode Layout Variations Work on Simulator but Disappears on Physical Device Xcode 5 iOS 5-不支持设备也不支持模拟器? - Xcode 5 iOS 5 - support neither for device nor for simulator? 在模拟器或物理设备上都无法在IOS中获得本地通知 - Not getting local notification in IOS neither on simulator nor on physical device xcode 9.2 IBAction和IBOutlet指示器未填写 - xcode 9.2 IBAction and IBOutlet indicators not getting filled in Xcode 不显示 UIButton 的 @IBAction - Xcode does not show @IBAction for UIButton React Native 字体大小在 Xcode/Simulator 与物理设备上有所不同 - React Native font size differs on Xcode/Simulator vs physical device 无法在物理设备或模拟器 Xcode 上运行我的应用程序 - Unable to run my app on physical device or simulator Xcode Xcode 没有在模拟器或连接的物理设备上运行更新的代码 - Xcode is not running updated code on the simulator or a connected physical device fcm onMessage 在模拟器上工作,但在物理设备上不起作用 - fcm onMessage works on simulator but does not work in physical device 准备好Cordova设备在xcode模拟器上不起作用,但在设备上工作 - Cordova device ready doesn't work on xcode simulator but work on device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM