【发布时间】:2020-10-27 03:54:00
【问题描述】:
当我运行应用程序时,如何在 storyLabel 文本、choice1Button 和choice2Button 中显示我的故事数组的第一行中的信息?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var storyLabel: UILabel!
@IBOutlet weak var choice1Button: UIButton!
@IBOutlet weak var choice2Button: UIButton!
let stories = [
Story(title: "You see a fork in the road", choice1: "Take a left", choice2: "Take a 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")
]
override func viewDidLoad() {
super.viewDidLoad()
updateUI()
}
@objc func updateUI() {
storyLabel.text = [1][0]
choice1Button.setTitle(choice1, for: .normal)
choice2Button.setTitle(Story[2], for: .normal)
}
@IBAction func choiceMade(_ sender: UIButton) {
}
}
【问题讨论】: