如何解决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 举报,一经查实,本站将立刻删除。