【发布时间】:2019-05-23 00:05:19
【问题描述】:
我对@987654321@ 有一个奇怪的问题,我有两个原型,第一个应该在indexPath.row=0 中绘制,第二个应该创建四次。
第二个原型包含一个 UIView 用于保存使用paintCode 应用程序创建的图标和一个文本标签。每个单元格还有四个图标。
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch indexPath.row {
case 0:
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell1", for: indexPath) as? ViewData {
return cell
}
case 1,2,3,4:
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell2", for: indexPath) as? ViewData {
switch indexPath.row {
case 1:
cell.dataIcon.is1stIcon = true
cell.title.text = "1"
case 2:
cell.dataIcon.is2ndIcon = true
cell.title.text = "2"
case 3:
cell.dataIcon.is3rdIcon = true
cell.title.text = "3"
case 4:
cell.dataIcon.is4thIcon = true
cell.title.text = "4"
default:
break
}
return cell
}
default:
break
}
return UICollectionViewCell()
}
问题是,所有文本都位于正确的位置(行),但indexPath.row=1 中的1stIcon 将显示在indexPath.row=3 中,而3rtIcon 将显示在indexPath.row=1 中。
首先我认为问题可能来自图标,但无论我放在这些行中,都有相同的错误趋势。
你对此有什么看法?
谢谢
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewcell indexpath