【发布时间】:2018-08-08 13:34:48
【问题描述】:
这是我第一次构建自己的应用程序,我需要帮助,该应用程序是关于测验的。
应用有很多素材,每种素材都有很多测验,这是QuizzesVC
我想从 QuizzesArray 传递数据(代码在下面) 到 QuestionVC
例如,当点击数学部分中的 Quiz 1 单元格时,QuestionVC 应显示数学数组的第一部分:
[Quiz(title: "Quiz1", ques: "1+2", choiceA: "3", choiceB: "2", choiceC: "4", correctAnswer: choiceA)]
QuizzesVC代码:
class QuizesVC: UITableViewController {
//...
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Quizes"
navigationController?.navigationBar.prefersLargeTitles = true
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
//...
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//...
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
//...
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//...
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}
}
这是 QuestionVC 代码:
class QuestionVC : UIViewController {
@IBOutlet var questionLabel: UILabel!//QuizzesArray: ques
@IBOutlet var choiceAButton: UIButton!//QuizzesArray: choiceA
@IBOutlet var choiceBButton: UIButton!//QuizzesArray: choiceB
@IBOutlet var choiceCButton: UIButton!//QuizzesArray: choiceC
}
这是QuizzesArray的代码:
class QuizzesArray {
var mathQuizes = [[Quiz(title: "Quiz1", ques: "1+2", choiceA: "3", choiceB: "2", choiceC: "4", correctAnswer: choiceA)],
[Quiz(title: "Quiz2", ques: "1+2", choiceA: "3", choiceB: "2", choiceC: "4", correctAnswer: choiceA)],
[Quiz(title: "Quiz3", ques: "1+2", choiceA: "3", choiceB: "2", choiceC: "4", correctAnswer: choiceA)],
[Quiz(title: "Quiz4", ques: "1+2", choiceA: "3", choiceB: "2", choiceC: "4", correctAnswer: choiceA)],
[Quiz(title: "Quiz5", ques: "1+2", choiceA: "3", choiceB: "2", choiceC: "4", correctAnswer: choiceA)],
[Quiz(title: "Quiz6", ques: "1+2", choiceA: "3", choiceB: "2", choiceC: "4", correctAnswer: choiceA)]
]
var chemistryQuizes = [[Quiz(title: "Quiz1", ques: "1+2", choiceA: "3", choiceB: "2", choiceC: "4", correctAnswer: choiceA)],
[Quiz(title: "Quiz2", ques: "1+2", choiceA: "3", choiceB: "2", choiceC: "4", correctAnswer: choiceA)],
[Quiz(title: "Quiz3", ques: "1+2", choiceA: "3", choiceB: "2", choiceC: "4", correctAnswer: choiceA)],
[Quiz(title: "Quiz4", ques: "1+2", choiceA: "3", choiceB: "2", choiceC: "4", correctAnswer: choiceA)],
[Quiz(title: "Quiz5", ques: "1+2", choiceA: "3", choiceB: "2", choiceC: "4", correctAnswer: choiceA)]
]
}
struct Quiz {
var title : String
var ques : String
var choiceA : String
var choiceB : String
var choiceC : String
var correctAnswer : Int
}
如果您需要更多解释,请告诉我。
【问题讨论】:
标签: arrays swift xcode uitableview