【发布时间】:2018-03-27 21:17:26
【问题描述】:
我有 UICollectionView,我正在下载图像并在单元格中显示它们。我的第一个单元格是屏幕宽度并包含一个按钮,其余的是一般单元格。该应用程序仅对前 2 个单元进行出队,应该有 3 个单元。
我的cellForItemAtIndexPath 功能:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.row == 0 {
print("yay")
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "UploadNewCell", for: indexPath) as! UploadNewCell
return cell
}else if indexPath.row > 0 {
let userImages = userposts[indexPath.row]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProfileCell", for: indexPath) as! ProfileCell
cell.fillCells(uid: uid!, userPost: userImages)
return cell
}else{
return ProfileCell()
}
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if indexPath.row == 0 {
print("hellowold")
} else {
let selecteditem : String!
selecteditem = userposts[indexPath.row]
performSegue(withIdentifier: "lol", sender: selecteditem)
}
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return userposts.count
}
我的看法:
单元格中应该有 3 个图像,其中一个在第一个索引中被 dequed。
我没有想法,关于解决方案有什么想法吗?
【问题讨论】:
-
"当我选择第一个索引上的单元格时,它没有按预期响应。"那个代码在哪里?
-
@Larme 更新问题和查询。单元格选择现在表现良好。将单元格出队是一个问题。再看问题。抱歉问错了。
-
部分返回的项目数...?
-
抱歉,我的机器出现问题。代码现已更新。感谢您的包容。
-
返回 userpost.count+1 in section 中的项目数
标签: ios swift3 uicollectionview uicollectionviewcell