Сould not dequeue a view of kind
Posted
技术标签:
【中文标题】Сould not dequeue a view of kind【英文标题】: 【发布时间】:2021-01-07 23:11:07 【问题描述】:错误:无法使类型视图出列:带有标识符 currencyCell 的 UICollectionElementKindCell - 必须为标识符注册一个 nib 或类或连接故事板中的原型单元
我不明白错误是什么。在故事板中,两个 collectionView 都有 ReuseIdentifier
还需要什么?
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource
// MARK: IBOutlets
@IBOutlet var currencyCollectionView: UICollectionView!
@IBOutlet var categoryCollectionView: UICollectionView!
let category = ["Popular", "Sports", "Insider", "Auto", "Science"]
// MARK: Private properties
private var currencyList: [Currency] = []
override func viewDidLoad()
super.viewDidLoad()
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
if collectionView == categoryCollectionView
return category.count
return currencyList.count
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "currencyCell", for: indexPath) as! CurrencyCollectionViewCell
cell.layer.cornerRadius = 10
cell.label.text = currencyList[indexPath.row].name
cell.value.text = currencyList[indexPath.row].value
if collectionView == categoryCollectionView
let categoryCell = collectionView.dequeueReusableCell(withReuseIdentifier: "categoryCell", for: indexPath) as! CategoryCollectionViewCell
categoryCell.categoryLabel.text = category[indexPath.row]
categoryCell.backgroundColor = .blue
return categoryCell
return cell
【问题讨论】:
网点已连接? 是的,在 CollectionViewCell 中 我的意思是集合视图本身 【参考方案1】:如果您使用的是 cellectionview 本身的单元格,您需要提供单元格标识符,如屏幕截图所示,并且它在代码中也必须相同,如下所示
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AppListCell", for: indexPath) as! CurrencyCollectionViewCell
【讨论】:
我写了所有的东西都在情节提要中说明了。以上是关于Сould not dequeue a view of kind的主要内容,如果未能解决你的问题,请参考以下文章
loaded some nib but the view outlet was not set(转载)
java.lang.IllegalArgumentException: You must not call setTag() on a view Glide is targeting
UISearchController Attempting to load the view of a view controller while it is deallocating is not
python 运行出现flask运行时提示出错了或者报服务器出错,ValueError: View function did not return a response
Warning: Attempt to present on whose view is not in the window hierarchy!
python_django_views文件中return render("XXXX/XXX.html") 显示 Template file not found