【发布时间】:2018-11-09 18:50:12
【问题描述】:
我正在尝试水平 UICollectionView 打印出 CoreData 条目,当我输入数据并尝试查看数据时,我没有收到任何错误,但数据不会在 UICollectionView 中打印出来。在 CoreData 中输入数据不是问题。下面是我在 UICollectionView 中获取 CoreData 并打印出来的代码,我哪里出错了?
class HistoryVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
var QBHistory = [QB]()
override func viewDidLoad() {
super.viewDidLoad()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return QBHistory.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "QBCollectionViewCell", for: indexPath) as! QBCollectionViewCell
do{
QBHistory = try context.fetch(QB.fetchRequest())
for each in QBHistory {
cell.QBName.text = each.qbName
cell.QBPotential.text = each.qbPotential
cell.QBValue.text = each.qbValue
cell.QBBust.text = String(each.qbBust)
cell.QBRound.text = each.qbRound
}
} catch {
print("oh no it broke")
}
return cell
}
}
【问题讨论】:
标签: ios swift core-data uicollectionview