0

我创建了两个类,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!)"这属于哪里?

4

1 回答 1

0

在回答您最初的问题时,可能是因为您的 if 和 else if 并不详尽:即 ifsnapshot.value!不等于 1 或 2。如果只有这两个可能的值,请尝试用 else 替换 else ifsnapshot.value!

于 2017-08-08T14:43:13.657 回答