我有四个按钮,我希望用户按。按钮值是1,5,25和100.如何将故事板中的多个按钮连接到Swift 3中的单个动作以增加值?
我有一个标签设置为显示按下按钮的所有值的总和。
但是,由于IBAction按钮的代码中有公式,因此数字不会相加。我在之前的帖子中看到,过去常常会出现一个“连接动作”,这将能够将故事板中的多个IBAction按钮连接到Swift的标志动作。我无法在Swift 3中找到该功能。
那么,如何将故事板中的多个IBActions按钮连接到Swift 3中的单个操作?后
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
var oneButtonTapped = 0
var noButtonTapped = 0
@IBAction func oneButtonTapped(_ sender: AnyObject) {oneButtonTapped = oneButtonTapped + 1
//Aware that the location of the code is requiring the 1 button to be tapped to be update. TODO: Have the total update after every button tap
let totalAmount = (noButtonTapped + oneButtonTapped + fiveButtonTapped + twentyfiveButtonTapped + hundredButtonTapped)
Amount.text = String(totalAmount)
}
var fiveButtonTapped = 0
@IBAction func fiveButtonTapped(_ sender: AnyObject) {fiveButtonTapped = fiveButtonTapped + 5
}
var twentyfiveButtonTapped = 0
@IBAction func twentyfiveButtonTapped(_ sender: AnyObject) {twentyfiveButtonTapped = twentyfiveButtonTapped + 25
}
var hundredButtonTapped = 0
@IBAction func hundredButtonTapped(_ sender: AnyObject) {hundredButtonTapped = hundredButtonTapped + 100
}
预先感谢您的协助
下面的代码放置,这是非常感谢!