Я пытаюсь сделать эту историю, в которой у пользователей есть два варианта. Теперь он работает только наполовину, и я просто не могу понять, почему он не меняет выбор кнопок. В основном это работает до второго if
оператора.
let startOfStory = [
Story(title: "You see a fork in the road", choice1: "Turn Left", choice2: "Turn Right"),
Story(title: "You see a tiger", choice1: "Shout for help", choice2: "Play Dead"),
Story(title: "You find a Treasure Chest", choice1: "Open it", choice2: "Check for Traps"),
]
var storyNumber = 0
override func viewDidLoad() {
super.viewDidLoad()
updateUI()
}
@IBAction func choiceMade(_ sender: UIButton) {
let userAnswer = sender.currentTitle
updateUI()
if userAnswer == startOfStory[0].choice1 {
storyLabel.text = startOfStory[1].title
} else if userAnswer == startOfStory[0].choice2 {
storyLabel.text = startOfStory[2].title
}
if userAnswer == startOfStory[1].choice1 {
storyLabel.text = startOfStory[0].title
} else if userAnswer == startOfStory[2].choice1 {
storyLabel.text = startOfStory[0].title
}
}
func updateUI() {
storyLabel.text = startOfStory[storyNumber].title
choice1Button.setTitle(startOfStory[storyNumber].choice1, for: .normal)
choice2Button.setTitle(startOfStory[storyNumber].choice2, for: .normal)
}