2017-03-25 52 views
0

我創建了兩類NumberTableViewCellYesNoTableViewCell,它們都有一個類型UITableViewCell。他們有動態的原型「附加」給他們(對不起,如果我說錯了話,我是新的術語)。tableView cellForRowAt返回自定義單元格錯誤

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!)"這屬於哪裏?

+1

**無法從異步完成塊**中返回某些內容。您需要重新設計工作流程。創建一個數據源數組,在'viewDidLoad'中填充數據源數組並重新加載tableview。 – vadian

+0

謝謝!一旦我做出改變,一切都變好了。謝謝! –

回答

0

爲了迴應您的原始問題,或許可能是因爲您的if和else並非詳盡無遺:即snapshot.value!不等於1或2.請嘗試替換其他,如果這些是唯一的兩個可能的值爲snapshot.value!

相關問題