我创建了两个类,NumberTableViewCell
它们YesNoTableViewCell
都有一个UITableViewCell
. 他们有“附加”到他们的动态原型(如果我说错了,请原谅,我是行话的新手)。
在override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
我连接到 firebase 时,根据数据库中的变量,我要么返回一个出列的可重用单元,要么返回另一个。我已经为此写出了所有代码,但是,返回给了我错误:
Unexpected non-void return value in void function
.
这是我的代码:
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!)"
这属于哪里?