2 fee s fee_S 于 2015.07.02 15:15 提问

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
}
    上下滑动后,单元格上的图片和字会混乱,求解。。

图片说明

1个回答

fee_S
fee_S   2015.07.02 16:16

问题解决了,需要自定义一下cell

Csdn user default icon
上传中...
上传图片
插入图片