gpt4 book ai didi

ios - tableView cellForRowAt 返回自定义单元格错误

转载 作者:行者123 更新时间:2023-11-30 12:34:40 25 4
gpt4 key购买 nike

我创建了两个类 NumberTableViewCellYesNoTableViewCell,它们的类型均为 UITableViewCell。它们“附加”了动态原型(prototype)(如果我说错了,请原谅,我对行话很陌生)。

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 中,我连接到 firebase 并根据数据库中的变量,我要么返回一个出列的可重用单元格,或其他。我已经为此写出了所有代码,但是,返回给了我错误:

void 函数中出现意外的非 void 返回值

这是我的代码:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

self.ref.child("campoutinfo").child("scoutQuestions").child("\(indexPath.row+1)").child("answer").observe(.value, with: { (snapshot) in
if "\(snapshot.value!)" == "1" {
var cell = tableView.dequeueReusableCell(withIdentifier: "yes-no_questionfield", for: indexPath) as! YesNoTableViewCell
return cell
} else if "\(snapshot.value!)" == "2" {
var cell = tableView.dequeueReusableCell(withIdentifier: "number_questionfield", for: indexPath) as! NumberTableViewCell
return cell
}
})
}

非常感谢任何帮助。提前致谢!

编辑:请记住,我确实还必须将代码放入某处:cell.questionLabel.text = "\(snapshot.value!)" 这属于哪里?

最佳答案

针对您最初的问题,也许可能是因为您的 if 和 else if 并不详尽:即 if snapshot.value! 不等于 1 或 2。尝试替换 else if与 else 一起,如果这是 snapshot.value!

仅有的两个可能值

关于ios - tableView cellForRowAt 返回自定义单元格错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43019260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com