我是 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()
的连接> 在操作旁边。
我猜你复制了 Reset 按钮来制作你的 Lap 按钮。如果在复制按钮时连接了 @IBAction
,那么您也可以通过新按钮获得该连接。因此,如果您将连接添加到新按钮,它不会取代之前的操作,而是成为第二个操作。
关于ios - 按下一个 UIButton 会触发另一个 UIButton : I don't want this to happen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44219430/