Firebaseの経験がある人はいますか?私はfirebase内にある情報をナビゲーションコントローラ内に表示しようとしています。私はプログラムを実行するたびに、情報が表示されていることを示しています。なぜなら、コマンドラインに何があっても印刷ラインが印刷されるからです。しかし、エラーがスローされます。FireToneの結果にUITableViewを接続してください
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
私の迅速なファイルはここにある:エラーをスローせずに
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()
})
:
//
// 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])
}
}
は私がで見つかったすべての情報をダウンロードします。
私はあなたのコードジェイを使用するたびに、値とキーの "オブジェクトの値がラップされていません"を取得し続けます。それは私には意味がありますが、何らかの理由でxコードが変数のキーと名前を読み込むのに問題があります。私はそれらを文字列として示すローカル変数を宣言しようとしました。 –
@AdrianAbles私のお詫び - どのchild.keyが何であるかを定義するのを忘れました: 'NSString'として答えを更新しました。上で定義したように、データ構造にservice_nameが含まれていなければならないことを忘れないでください。 – Jay
no pronlem Jay!私は本当にあなたの助けに感謝します。私はちょうどNSStringを変更し、プロジェクトをきれいにし、データ構造を変更しましたが、同じエラーがまだ発生しています。また、値の直前で発生しているエラーが発生していると私はなぜそれがわからない。エラーは「?」を配置しようとし続けます。または '!'値の後に。 –