首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与IBAction链接的UIButton在物理设备或Xcode9.2中的模拟器的模拟中不起作用

与IBAction链接的UIButton在物理设备或Xcode9.2中的模拟器的模拟中不起作用
EN

Stack Overflow用户
提问于 2018-01-10 10:14:55
回答 1查看 169关注 0票数 0

我使用sure +拖动添加了UIButton,添加了随机数字的变量和arc4random,然后使用front函数测试我的按钮以确保它工作。但是按钮完全没有响应,并且我的代码中没有错误。

代码语言:javascript
复制
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
    }
}
EN

回答 1

Stack Overflow用户

发布于 2018-01-10 17:37:35

以编程方式分配操作。

代码语言:javascript
复制
yrBtnOutlet.addTarget(self, action: #selector(self. rollButtonPressed(_:)), for: .touchUpInside)

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48179334

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档