StoryLine类型的应用-未显示正确的标签

问题描述

使用Swift的大型菜鸟,并正在通过在线课程:)) 我试图获得一个非常简单的Story Line应用,以在按下按钮时显示不同的Label。 基本上开始MVC方法课程。现在,我编写了代码,以为可以工作,但是很遗憾,它没有返回正确的标签 有什么建议吗?

Import UIKit

class ViewController: UIViewController {


@IBOutlet weak var storyLabel: UILabel!
@IBOutlet weak var choice1Button: UIButton!
@IBOutlet weak var choice2Button: UIButton!

let story0 = "You see a fork in the road"
let choice1 = ["Take a left","Shout for help","Open it"]
let choice2 = ["Take a right","Play dead","Check for traps"]
let stories = [
    "You see a fork in the road","You see a tiger","You find a treasure chest"
]

override func viewDidLoad() {
    super.viewDidLoad()
    updateUI()
    
}
@IBAction func choiceMade(_ sender: UIButton) {
    
    let userpressedChoice = choice1
    
    if userpressedChoice == [choice1[0]] {
        storyLabel.text = stories[1];
        choice1Button.setTitle(choice1[1],for: []);
        choice2Button.setTitle(choice2[1],for: [])

    } else {
        storyLabel.text = stories[2];
        choice1Button.setTitle(choice1[2],for: []);
        choice2Button.setTitle(choice2[2],for: [])
    }
}
func updateUI() {
    storyLabel.text = stories[0]
    choice1Button.setTitle(choice1[0],for: [])
    choice2Button.setTitle(choice2[0],for: [])
    }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)