从firebase检索数据到tableview(EXC_BAD_INSTRUCTION错误)

时间:2016-07-26 21:32:15

标签: ios swift uitableview firebase-realtime-database

我正在尝试从firebase检索数据到tableview。我在一个单元格中有三个标签作为评论标题,评论和日期。每个标签在原型单元格中都有一个标签(1,2,3),我有以下代码

enter image description here

struct commentStruct {
let title : String!
let comment : String!
let date : String!
 }


class ListComments: UITableViewController {

var comments = [commentStruct]()



override func viewDidLoad() {
    super.viewDidLoad()

    self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")


    let root = FIRDatabase.database().reference()

    root.child("Comments").queryOrderedByKey().observeEventType(.ChildAdded, withBlock: {
        snapshot in

        let t = snapshot.value!["title"] as! String
        let c = snapshot.value!["comment"] as! String
        let d = snapshot.value!["date"] as! String!

        self.comments.insert(commentStruct(title:t , comment:c , date:d), atIndex: 0)
        self.tableView.reloadData()

    })


}

我的cellForRowAtIndexPath方法是

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var cell = tableView.dequeueReusableCellWithIdentifier("Cell")




    let label1 = cell!.viewWithTag(1) as! UILabel
    label1.text = comments[indexPath.row].title


    let label2 = cell!.viewWithTag(2) as! UILabel
    label2.text = comments[indexPath.row].comment

    let label3 = cell!.viewWithTag(3) as! UILabel
    label3.text = comments[indexPath.row].date

    return cell!

     }


  }

我收到错误EXC_BAD_INSTRUCTION(code = EXC_i386_INVOP)

0 个答案:

没有答案