为什么我的图像在使用indexPath的UICollectionView中没有变化?

时间:2015-12-17 04:58:21

标签: ios swift mobile swift2

我有一个Collection View,其中包含我已定义的ImageCollectionViewClass以及图像的类。但是,集合视图中的图像并没有随indexPath变化,我无法解决原因

class metricImage {
    var featuredImage: UIImage!

    init(featuredImage: UIImage!){
        self.featuredImage = featuredImage
    }

    static func createImage() -> [metricImage] {
        return [metricImage(featuredImage: UIImage(named: "prodOne.png")!), metricImage(featuredImage: UIImage(named: "prodTwo.png")!), metricImage(featuredImage: UIImage(named: "prodThree.png")!),metricImage(featuredImage: UIImage(named: "prodFour.png")!),metricImage(featuredImage: UIImage(named: "prodFive.png")!),metricImage(featuredImage: UIImage(named: "prodSix.png")!)]
    }


}

class ImageCollectionViewCell: UICollectionViewCell
{

    var images: metricImage! {
        didSet{
            updateUI()
        }
    }
    @IBOutlet weak var featuredImageView: UIImageView!

    private func updateUI() {
        featuredImageView?.image! = images.featuredImage
    }

}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    if collectionView == prodCollectionView {
        //print("collectionViewOne")
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("productCell", forIndexPath: indexPath) as! ImageCollectionViewCell
        print(indexPath.item)
        cell.images = self.prodImage[indexPath.item]
        return cell
    }

我添加了一些语句以确保它进入所需的位置。我是新手,所以它可能是微不足道的。提前谢谢

0 个答案:

没有答案