我已经有 2 天无法理解我的问题了,它有点难以描述,但我会尝试。 我的代码:
import UIKit
class ViewController: UIViewController {
let heroes = ["Abaddon", "Alchemist", etc...]
let skills = ["Curse of Avernus", etc...]
var scoring = 0
var scoringStraight = 0
var chosenHeroes = [Int] ()
var shuffled = [Int] ()
@IBOutlet weak var score: UILabel!
@IBOutlet weak var scoreStraight: UILabel!
@IBOutlet weak var skillName: UILabel!
@IBOutlet weak var firstButton: UIButton!
@IBOutlet weak var secondButton: UIButton!
@IBOutlet weak var thirdButton: UIButton!
@IBOutlet weak var fourthButton: UIButton!
func fourBesties () {
var fourHeroes = [Int] ()
while fourHeroes.count != 4 {
let random = Int.random(in: 0..<heroes.count)
if !chosenHeroes.contains(random) && !fourHeroes.contains(random) {
fourHeroes.append(random)
}
}
chosenHeroes.append(fourHeroes.last!)
shuffled = fourHeroes.shuffled()
}
func progressCheck () {
if chosenHeroes.count == 4 {
let chosenLast = chosenHeroes.last!
chosenHeroes.removeAll()
chosenHeroes.append(chosenLast)
}
}
@IBAction func touch(_ sender: UIButton) {
progressCheck()
viewDidLoad()
var mainTag = 0
for i in 0...3 {
if shuffled[i] == chosenHeroes.last {
mainTag = i
}
}
if sender.tag == mainTag {
scoring += 1
scoringStraight += 1
}
else {
scoringStraight = 0
}
score.text = ("Score \(scoring)")
scoreStraight.text = ("\(scoringStraight) in a row")
}
override func viewDidLoad() {
super.viewDidLoad()
fourBesties()
skillName.text = ("\(skills[chosenHeroes.last!])")
firstButton.setTitle(heroes[shuffled[0]], for: .normal)
secondButton.setTitle(heroes[shuffled[1]], for: .normal)
thirdButton.setTitle(heroes[shuffled[2]], for: .normal)
fourthButton.setTitle(heroes[shuffled[3]], for: .normal)
}
}
所以,是的,问题所在。问题是:当我点击应用程序内的按钮时,屏幕上会显示上一个操作的标签,而 sender.tag 已经在下一个操作中。我很难正确解释它,所以如果你不明白我会举个例子。
2个问题:
所以,再次对这个描述感到抱歉,如果有人明白我在说什么,请告诉我。另外,如果你明白如何更正确地描述我的问题,也让我知道,我会改变话题
2 天尝试了很多东西,完全更改了代码,更改了 viewLoad,按钮操作,交换了它们等等,仍然不知道该怎么做