2017-03-25 10 views
0

UITableViewCell의 두 클래스 인 NumberTableViewCellYesNoTableViewCell을 만들었습니다. 동적 프로토 타입이 그들에게 "부착"되어 있습니다 (내가 잘못 말하면 실례지만, 나는 용어에 새로운 것입니다).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 if가 완전하지 않을 수 있습니다. 즉 snapshot.value!이 1 또는 2가 아닌 경우 일 수 있습니다. 가능한 값 snapshot.value!