ios - 按下一个 UIButton 会触发另一个 UIButton : I don't want this to happen

标签 ios swift xcode uibutton

我是 swift 和 xcode 的新手,在创建这个带有 laps 的简单计时器应用程序时遇到了一些麻烦。当我按下“膝上”按钮时,也会触发“重置按钮”。谁能帮我解决这个问题?这些按钮彼此相邻,但我认为这与它没有任何关系。此外,我还注释掉了 lap 函数的整个主体,同样的事情发生了。

 @IBAction func Reset(_ sender: Any)
{
    min = 0
    sec = 0
    mil = 0
    timer.invalidate()
    createLabel()
    var i = 0
    while i < list.count
    {
        list[i].removeFromSuperview()
        i = i + 1
    }
    running = false

}



@IBAction func Lap(_ sender: UIButton)
{

    let word = UILabel()
    list.append(word)

    word.font = UIFont.systemFont(ofSize: 50)
    word.text = make()
    word.sizeToFit()

    word.frame.origin = CGPoint(x:187.5,y:700)
    self.Scroll.addSubview(word)
    word.center = CGPoint(x:187,y:last)
    last = last + 50


    Scroll.contentSize.height = Scroll.contentSize.height + 50

}

最佳答案

听起来您将两个 @IBAction 连接到您的 Lap 按钮。 Control - 在Storyboard 中单击您的 Lap 按钮,然后通过单击 x 删除与 Reset() 的连接> 在操作旁边。

unhook IBAction in Storyboard

我猜你复制了 Reset 按钮来制作你的 Lap 按钮。如果在复制按钮时连接了 @IBAction,那么您也可以通过新按钮获得该连接。因此,如果您将连接添加到新按钮,它不会取代之前的操作,而是成为第二个操作。

关于ios - 按下一个 UIButton 会触发另一个 UIButton : I don't want this to happen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44219430/

相关文章:

swift - PHAsset 到 UIImage

ios - 无法在调度队列中手动控制 performSegue()

ios - 无法将类型 'UILabel!' 的值转换为预期参数 'type inout String'

ios - 全局更改导航栏后退按钮图像大小

swift - 我需要该应用程序定期从网络下载并处理少量内容(快速)

ios - 1 个架构 x86_64 的重复符号

iphone - 如何使 UINavigationBar 不下推 View ?

ios - XMPP 上次事件时间以奇怪的形式显示。如何解决?

javascript - "Run JavaScript on Web Page"的 iOS 12 快捷方式设置问题

ios - Xcode SwiftGen : build fails in project with multiple targets