Tag: uicollectionview uicollectionviewcell

UItableviewCell全部取消select

我有一个FollowVC和FollowCell安装与集合视图。 我可以使用下面的代码正确显示所有的数据到我的uIcollection视图单元中,没有问题。 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { if let cell = collectionView.dequeueReusableCellWithReuseIdentifier("FollowCell", forIndexPath: indexPath) as? FollowCell { let post = posts[indexPath.row] cell.configureCell(post, img: img) if cell.selected == true { cell.checkImg.hidden = false } else { cell.checkImg.hidden = true } return cell } } 请注意,我也可以使用以下代码select和取消select多个图像 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { […]

UICollectionViewCell内容在第一次加载时大小错误

我有一个UICollectionView添加到我的UIViewController并为它定制了一个单元格。 我使用sizeForItemAtIndexPath方法设置单元格的大小,并将每个单元格的高度和宽度设置为UIScreen.mainScreen().bounds.width/2 。 所以基本上,每个单元的宽度是屏幕宽度的一半,长度也是相同的。 然后在单元格内部有一个UIImageView ,每个边缘固定在单元格的相对边缘,以便图像视图填充单元格。 我也有一个UILabel在单元格中垂直和水平居中。 然而,在第一次加载时,单元格的尺寸是正确的,但是在左上方的一个小方格中内容要小得多。 (如下图所示,我将单元格的contentView背景颜色设置为绿色,将imageView背景颜色设置为红色)。 然后,向下滚动一下(我假设一个可重用的单元格正在出列),所有的单元格都很好(滚动后保持不变)。 什么是导致内容在第一次加载时不能被正确地约束? UPDATE 我的UIViewController一些代码: func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var cell = collectionView.dequeueReusableCellWithReuseIdentifier("PrevDrawCell", forIndexPath: indexPath) as? PrevDrawCell if cell == nil { cell = PrevDrawCell() } cell!.drawVC = self cell!.imageShortCode = self.tempImageURLs[indexPath.row] // Pull image (async) and set after download cell!.setupImage() cell!.contentView.backgroundColor […]