【发布时间】:2016-03-12 20:20:04
【问题描述】:
我目前正在尝试使用 Firebase UI 来使用自定义单元格填充 UITableView。不幸的是,证明很困难,并且以前建议的修复方法不起作用。
文档 (https://github.com/firebase/FirebaseUI-iOS#using-storyboards-and-prototype-cells) 证明了这一点:
self.dataSource = FirebaseCollectionViewDataSource(ref: firebaseRef cellClass: YourCustomClass.self cellReuseIdentifier: @"<YOUR-REUSE-IDENTIFIER>" view: self.collectionView)
self.dataSource.populateCellWithBlock { (cell: YourCustomClass, obj: NSObject) -> Void in
// Populate cell as you see fit
cell.customView = customView;
}
self.collectionView.dataSource = self.dataSource;
复制这个并插入我自己的 TableViewCellClass 会产生这个错误:
无法将类型 '(ManageTableViewCell, NSObject) -> Void' 的值转换为预期的参数类型 '(UITableViewCell, NSObject) -> Void'
然后我看到了这个问题线程 (https://github.com/firebase/FirebaseUI-iOS/issues/16),其中一个 Firebase 团队说强制转换会像这样工作:
self.dataSource.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in
// Populate cell as you see fit, like as below
var customCell = cell as! CustomTableViewCell;
let snapshot = obj as! FDataSnapshot; // danger this can be null on deletion!
}
但是这会立即产生错误:
不能从 'UITableViewCell' 到更可选的类型 'ManageTableViewCell!'
有没有人对如何做到这一点有任何建议。这似乎是一个没有真正解决办法的常见问题。
【问题讨论】:
-
什么是
ManageTableViewCell?向我们展示您的 populateCellWithBlock 的外观。从文档中给我们提供示例并没有多大帮助 -
我刚刚发现了@FruitAddict 的问题 - 已在答案中发布。
标签: swift firebase uitableview firebaseui