【发布时间】:2015-08-18 15:11:56
【问题描述】:
我在我的 iOS 应用中使用 Firebase-UI-IOS。当我运行该应用程序时,我收到以下错误:
致命错误:“在展开 Optional 时意外发现 nil 价值”。
这是我在ViewDidLoad中的代码:
let ref = Firebase(url: "https://XXXXXX.firebaseio.com")
var dataSource: FirebaseCollectionViewDataSource!
let messageRef = ref
.childByAppendingPath("brainstorms")
.childByAppendingPath(invite.brainstormId)
.childByAppendingPath("messages")
self.dataSource = FirebaseCollectionViewDataSource(ref: messageRef, cellClass: MessageCollectionViewCell.self, reuseIdentifier: "messageCell", view: self.collectionView)
self.dataSource.populateCellWithBlock { (cell: UICollectionViewCell, obj: NSObject) -> Void in
// Populate cell as you see fit
if let cell = cell as? MessageCollectionViewCell {
println(cell)
cell.messageText.text = "Hello world" <--- ERROR HERE
}
}
self.collectionView.dataSource = self.dataSource
我试图解开 cell.messageText,但它总是返回 nil。我的单元班MessageCollectionViewCell 已在我的故事板中注册。
我的println(cell) 打印以下行:<xxxxx.MessageCollectionViewCell: 0x7fc26d8d9080; baseClass = UICollectionViewCell; frame = (17.5 155; 340 80); layer = <CALayer: 0x7fc26d8d92e0>>。
这在我看来应该可以工作。可以参考populateCellWithBlockhere。
有人有什么建议吗?
【问题讨论】:
标签: ios iphone swift uicollectionview firebase