ios - IBAction 按钮保持事件状态

标签 ios swift xcode ibaction iboutlet

我有 2 个按钮,每个按钮都在下面,根据功能,它会显示启用的按钮和禁用的按钮。

@IBOutlet weak var startBtn: workoutButton!
@IBOutlet weak var restBtn: workoutButton!

@IBAction func startBtnPressed(_ sender: AnyObject) {
        startBtn.isHidden = true
        startBtn.isEnabled = false
        perform(#selector(workoutStartVC.revealRestModeBtn), with: 1, afterDelay: 10)
        timeLeft = 0
        myTimer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(workoutStartVC.timerRunning), userInfo: nil, repeats: true)
    }

    @IBAction func restBtnPressed(_ sender: AnyObject) {
        print("rest mode button is pressed and i am showing a overlay right now with data count down")
    }

当单击 restBtn 时,它仍会执行 startBtnPressed 中的代码。这怎么可能?因为当我单击 startBtnPressed 1 次时,它应该禁用该按钮并将其隐藏。它隐藏了它,但我仍然能够执行该功能。所以计时器走得快了一倍。

感谢您的帮助!

凯文。

最佳答案

打开您的 Storyboard,选择 resetButton 并确保“已发送事件”部分中仅附加了一个操作。现在您将看到附加到它的两个 IBAction。

应该是这样的:

enter image description here

你可能有这样的事情:

enter image description here

关于ios - IBAction 按钮保持事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39983252/

相关文章:

ios - 将 UITabBarSystemItem 图标与其他按钮一起使用

xcode - 制作一个包含姓名和号码的列表,swift xcode

ios - 从API加载图像

iphone - 如何估计 UITextField 的适当高度,以保存给定字体大小的文本

iphone - 在 iOS 3 但不是 iOS 4 中的 applicationWillEnterForeground 上的 EXC_BAD_ACCESS

ios - 通过 UIActivityViewController (Twitter, Facebook, Instagram) 使用主题标签分享图片

ios - 防止 iAd 转移其他 View

iphone - 使用带有 ARC 的 ios5 选择地址簿地址

ios - 在iOS Swift中从设备获取图像的URL路径

ios - UITextView 未在键盘中显示地球图标