【发布时间】:2016-04-11 00:15:17
【问题描述】:
有人对 Firebase 有任何经验吗?我正在尝试将我在 firebase 中的信息显示在导航控制器中。每当我运行程序时,信息都会显示它正在被接收,因为我有打印行将它接收到的任何内容打印到命令提示符,但是会引发错误。
NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier CellIdentifier - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
我的 swift 文件在这里:
//
// All.swift
// Guaranteed Pricing
//
// Created by DePauw on 3/30/16.
// Copyright © 2016 DePauw. All rights reserved.
//
import Foundation
import UIKit
import Firebase
class All: UINavigationController, UITableViewDataSource, UITableViewDelegate {
var items: [String] = []
var tableView: UITableView!
let cellIdentifier = "CellIdentifier"
override func viewDidLoad(){
super.viewDidLoad()
self.tableView = UITableView(frame:self.view!.frame)
self.tableView!.delegate = self
self.tableView!.dataSource = self
self.tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
self.view?.addSubview(self.tableView)
let ref = Firebase(url:"https://<firebase-id>.firebaseio.com/services")
ref.observeSingleEventOfType(.Value, withBlock: { snapshot in
// do some stuff once
print(snapshot.value)
// get these values and put them in the cell's text view. key is more important
print(snapshot.key)
// add to the array and just this array
self.items.append(snapshot.key)
self.tableView!.reloadData()
})
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath)
// Fetch Fruit
let fruit = items[indexPath.row]
// Configure Cell
cell.textLabel?.text = fruit
return cell
}
// onclick printing
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print(items[indexPath.row])
}
}
我想下载在以下位置找到的所有信息:
let ref = Firebase(url:"https://<firebase-id>.firebaseio.com/services")
ref.observeSingleEventOfType(.Value, withBlock: { snapshot in
// do some stuff once
print(snapshot.value)
// get these values and put them in the cell's text view. key is more important
print(snapshot.key)
// add to the array and just this array
self.items.append(snapshot.key)
self.tableView!.reloadData()
})
不抛出错误。这是我的故事板:
【问题讨论】:
标签: ios json swift uitableview firebase