【发布时间】:2017-04-06 13:11:54
【问题描述】:
大家好,我遇到了一个问题,无法在任何地方找到解决方案。谁能告诉我这是什么问题,我刚刚开始快速学习我想从我的 firebase 数据库中获取数据并将其打印在 uitableviewcell 上
我创建了一个 swift 文件,其中包含
类分类:NSObject { var 类别:字符串? }
我的视图控制器在下面
import UIKit
import FirebaseDatabase
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var categoryList = [Categories]()
var refHandle:UInt!
var ref:FIRDatabaseReference?
@IBOutlet weak var listOfCategories: UITableView!
@IBOutlet weak var menuBtn: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
ref = FIRDatabase.database().reference()
menuBtn.target = revealViewController()
menuBtn.action = #selector(SWRevealViewController.revealToggle(_:))
fetchCategories()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return categoryList.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
// Set cell content
cell.textLabel?.text = categoryList[indexPath.row].categories
return cell
}
func fetchCategories(){
refHandle = ref?.child("Categories").observe(.childAdded, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
print(dictionary)
let categories = Categories()
categories.setValuesForKeys(dictionary)
self.categoryList.append(categories)
DispatchQueue.main.async
{
self.listOfCategories.reloadData()
}
}
})
}
}
我的数据库
-Categories
-name
Bikes:"Bikes"
Cars:"Cars"
Cats:"Cats"
如果我打印(categorList)我也没有在控制台上得到它。下面是日志
2017-04-06 06:09:50.531 壁纸应用[1716] [Firebase/Analytics][I-ACS023007] Firebase Analytics v.3700000 已启动 2017-04-06 06:09:50.534 壁纸应用[1716] [Firebase/Analytics][I-ACS023008] 要启用调试日志记录,请设置 以下应用程序参数:-FIRAnalyticsDebugEnabled(请参阅 http://goo 。 gl/RfcP7r) 2017-04-06 06:09:50.565 壁纸应用[1716] [Firebase/Analytics][I-ACS003007] 成功创建 Firebase Analytics 应用程序自动委托代理。要禁用 代理,将标志 FirebaseAppDelegateProxyEnabled 设置为 NO Info.plist 2017-04-06 06:09:50.580 壁纸应用[1716] [Firebase/Analytics][I-ACS005000] AdSupport 框架不是 当前链接。某些功能将无法正常运行。学到更多 在http://goo。 gl/9vSsPb 2017-04-06 06:09:50.589 壁纸应用[1716] [Firebase/Analytics][I-ACS023012] Firebase 分析已启用 [“汽车”:汽车,“自行车”:自行车,“猫”:猫] 2017-04-06 06:09:52.565 壁纸应用程序[1716:28745] * 由于未捕获而终止应用程序 异常“NSUnknownKeyException”,原因: '[ setValue:forUndefinedKey:]:这个类不是键值 符合关键汽车的编码。 * 第一次抛出调用堆栈:( 0 CoreFoundation 0x0000000104725d4b exceptionPreprocess + 171 1 libobjc.A.dylib
0x0000000103d6621e objc_exception_throw + 48 2 核心基础
0x0000000104725c99 -[NSException raise] + 9 3 基础
0x00000001038749df -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291 4 基础 0x00000001038d672f -[NSObject(NSKeyValueCoding) setValuesForKeysWithDictionary:] + 301 5 壁纸应用程序 0x00000001026fe886 _TFFC14Wallpapers_App14ViewController15fetchCategoriesFT_T_U_FCSo15FIRDataSnapshotT_ + 1126 6 壁纸应用程序 0x00000001026fed8c _TTRXFo_oCSo15FIRDataSnapshot__XFdCb_dS_ + 60 7 壁纸应用程序 0x00000001027c85b0 63-[FIRDatabaseQuery observeEventType:withBlock:withCancelBlock:]_block_invoke + 37 8
壁纸应用程序 0x00000001027efeb3 __43-[FChildEventRegistration fireEvent:queue:]_block_invoke.68 + 88 9 libdispatch.dylib 0x0000000107470978 _dispatch_call_block_and_release + 12 10 libdispatch.dylib 0x000000010749a0cd _dispatch_client_callout + 8 11 libdispatch.dylib 0x000000010747a8a4 _dispatch_main_queue_callback_4CF + 406 12 核心基础 0x00000001046e9e49 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9 13 核心基础 0x00000001046af37d __CFRunLoopRun + 2205 14 CoreFoundation 0x00000001046ae884 CFRunLoopRunSpecific + 420 15 图形服务
0x0000000109439a6f GSEventRunModal + 161 16 UIKit
0x000000010525cc68 UIApplicationMain + 159 17 壁纸应用
0x0000000102701fcf main + 111 18 libdyld.dylib
0x00000001074e668d 开始 + 1 ) libc++abi.dylib: 终止于 NSException (lldb) 类型的未捕获异常
【问题讨论】:
标签: ios uitableview firebase swift3 firebase-realtime-database