ARTICLE AD BOX
I have been trying to press the button, but when I do they do not work, and are unresponsive. I have been trying to fix it, but it has failed time and time again. Please show pictures and explain the solution like a 5 year old. The display for the plot works just fine, but It just can't show, just when I load my xcode project it works, just when I press the buttons, they do not work. I tried to find a solution through the in built AI; but it was really complicated and just, I needed prper guidance, like with images. It it unresponsive
import UIKit class ViewController: UIViewController { struct Story { let title: String let option1: String let option2: String } // Story nodes let plot1 = Story(title: "You find a fork in the road", option1: "Take a left", option2: "Take a right") let plot2 = Story(title: "You found a tiger", option1: "Eat it", option2: "Go to the hospital") let plot3 = Story(title: "3", option1: "4", option2: "5") let plot4 = Story(title: "6", option1: "", option2: "") let plot5 = Story(title: "7", option1: "8", option2: "9") let plot6 = Story(title: "10", option1: "", option2: "") let plot7 = Story(title: "11", option1: "", option2: "") let plot8 = Story(title: "12", option1: "", option2: "") @IBOutlet weak var storyLabel: UILabel! @IBOutlet weak var choice1Button: UIButton! @IBOutlet weak var choice2Button: UIButton! var questionNumber = 0 override func viewDidLoad() { super.viewDidLoad() // Set initial story changeButton(to: plot1) } // Expose as IBAction and connect both buttons to this action in Interface Builder. @IBAction func buttonPressed(_ sender: UIButton) { print("Button pressed with tag:", sender.tag, "questionNumber:", questionNumber) // ... // Use button tags: 1 for left/option1, 2 for right/option2 switch (questionNumber, sender.tag) { case (0, 1): // From start, choosing option1 leads to plot2 changeButton(to: plot2) questionNumber = 1 case (0, 2): // From start, choosing option2 leads to plot3 changeButton(to: plot3) questionNumber = 1 case (1, 2): // From plot2, choosing option2 returns to plot1 (example logic) changeButton(to: plot1) questionNumber = 2 case (2, 1): // From question 2, choosing option1 goes to plot5 changeButton(to: plot5) case (2, 2): // From question 2, choosing option2 goes to plot4 changeButton(to: plot4) default: print("Unhandled state: questionNumber=\(questionNumber), tag=\(sender.tag)") break } } // Helper to update UI for a given story func changeButton(to story: Story) { storyLabel.text = story.title choice1Button.setTitle(story.option1, for: .normal) choice2Button.setTitle(story.option2, for: .normal) } }