我正在尝试设置一个问题及其相应的答案,并将其写入一个表视图中,每个单元格表示字典和问题中的一个答案。
字典的设置如下:
struct Quest {
question: String,
ans1: String,
ans2: String,
ans3: String,
ans4: String,
cor: String
}该结构可以容纳从1个问题到100个问题的任意位置
我试图调用reloadata()函数,但这会在每个单元格中加载一个不同的问题,而我需要先加载问题,然后加载四个答案。只是不确定如何做到这一点。
下面是我的cellFor代码:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath)
let label1 = cell.viewWithTag(1) as? UILabel
let myView = cell.viewWithTag(3)
let myItem = items[indexPath.row]
print(indexPath.row)
label1?.text = "Question"
return cell我试着让它返回单元格,然后添加下面的代码来加载下一个单元格,但它一直告诉我,一旦我返回,剩下的代码就不会执行,我明白这一点。
任何帮助都将不胜感激。
发布于 2020-09-16 09:02:10
这听起来像是您需要一个分段的表格视图,每个部分在小节标题中包含问题,在该部分的单元格中包含答案。
https://stackoverflow.com/questions/63906781
复制相似问题