0
こんにちは、私は私のUICollectionViewに問題があります。まず、私は、URL画像を含むサーバーから来る画像のリストを持っています。Swift Collection無作法の画像null null
しかし、URLがnullのとき、セルがランダムに画像を見せています。 URLがnullの場合は、画像が表示されません。
私はUIImageViewに画像を表示するためSDWebImageを使用しています。 UICollectionViewCell
として
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return listData.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as! MyCollectionListViewCell
if let url = self.listData[indexPath.row]["photo"] as? String {
let urlPhoto = NSURL(string:url!)
cell.imageView.sd_setImageWithURL(urlPhoto, placeholderImage:img)
cell.imageView.contentMode = UIViewContentMode.ScaleAspectFill
cell.imageView.layer.masksToBounds = true
cell.imageView.clipsToBounds = true
}
}
感謝を... ..! – Voyager