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