swift - 无法将一种视图出列:UICollectionElementKindCell 与 Deferent ViewController 上的标识符
问题描述
**我已经在不同的视图控制器上设置了标识符,但它告诉我我必须为标识符注册一个 nib 或一个类,或者在情节提要中连接一个原型单元'**
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == self.secondCollectionView {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "myCell", for: indexPath) as! CollectionViewCell
cell.mainText.text = Imgname[indexPath.item]
cell.mainImageView.image = mainImg[indexPath.item]
return cell
}
else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "secondCell", for: indexPath) as! SecondCollectionViewCell
cell.secondText.text = Imgname[indexPath.item]
cell.secondImage.image = mainImg[indexPath.item]
return cell
}
}
解决方案
var cell: UICollectionViewCell!
if .....{
cell =
} else {
cell =
}
return cell
需要在函数中编写这种风格的代码
推荐阅读
- android - 如何确保我的 android 应用使用矢量而不是 PNG?
- android - 为目标 API 级别 29 编译时,在 Android API 级别 < 24 上访问 NMEA?
- azure-cognitive-search - Azure 搜索复杂结构 sql 数据源
- vue.js - 以下运算符'!!'的VueJS含义
- html - 如何调整包括图像在内的 webview 内容的大小以适应水平边界
- css - 将动画 SVG 停止到屏幕上的某个位置
- node.js - 亚马逊 Alexa 的技能购买追加销售不起作用
- matrix - 将列向量转换为R中矩阵的对角线?
- c# - Xamarin 表单 - 文件系统
- c# - WebHost 重新启动并丢失令牌验证