问题描述
- Swift coollectionView cell重用
-
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("EntryCell", forIndexPath: indexPath) as! EntryCell let wdgt_icon = self.homesArr[indexPath.item].objectForKey("wdgt_icon") as? String //设置颜色 let wdgt_color = self.homesArr[indexPath.item].objectForKey("wdgt_color") as? String cell.backgroundColor = color(wdgt_color!) //设置标题 let titleLabel = UILabel(frame: CGRectMake(10, 0, 80, 30)) titleLabel.textColor = UIColor.whiteColor() cell.contentView.addSubview(titleLabel) titleLabel.text = self.homesArr[indexPath.item].objectForKey("wdgt_title") as? String //设置icon let picLabel = UILabel(frame: CGRectMake(10, 40, 80, 40)) picLabel.textColor = UIColor.whiteColor() cell.contentView.addSubview(picLabel) picLabel.text = self.iconDict[wdgt_icon!] let font:UIFont = UIFont(name: "FontAwesome", size: 40)! picLabel.font = font println(titleLabel.text) return cell } 上下滑动后,单元格上的图片和字会混乱,求解。。
解决方案
问题解决了,需要自定义一下cell
时间: 2024-11-03 16:00:00