【发布时间】:2017-05-17 07:25:17
【问题描述】:
我在 uicollectionview 中将多个单元格出列时遇到问题。 有人可以逐步解释从注册到出队的过程。我在网上找不到与在一个集合视图中加载两个或多个 uicollectionview 单元格有关的任何内容。同样,这是为了基于 coreadata 中的变量在单个集合视图中加载多种类型的单元格。
这是我目前所拥有的。
这里是我注册单元格的地方
collectionView?.register(ShareCell.self, forCellWithReuseIdentifier: cellId)
collectionView?.register(ShareCellMedia.self, forCellWithReuseIdentifier: mediaCellId)
这是我在索引路径中的项目单元格
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath :
IndexPath) -> UICollectionViewCell {
let friend = fetchedResultsController.object(at: indexPath) as! Friend
if (friend.lastMessage?.hasImage)! == true {
let mediaCell = collectionView.dequeueReusableCell(withReuseIdentifier: mediaCellId, for: indexPath) as!
ShareCellMedia
mediaCell.cell = friend.lastMessage
return mediaCell
}else{
let regularCell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as!
ShareCell
regularCell.cell = friend.lastMessage
return regularCell
}
}
【问题讨论】:
-
您发布的代码看起来不错。你没想到会发生什么?您确定在使用之前设置了 cellId 和 mediaCellId 吗?何时注册单元格,您确定此时 collectionView 不为零吗?
标签: ios swift xcode uicollectionview