此擴展在CollectionView中只提供一個UIImageView。如何顯示更多圖像,取決於照片數組的大小。照片數組包含Url到圖像的數組(字符串)。如何在UICollectionView中顯示多個圖像Swift
extension FlatViewController: UICollectionViewDataSource{
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return (flat.photos?.count)!
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CustomCollectionViewCell
cell.imageView.loadImageFromURL(NSURL(string: flat.image!)!)
return cell
}
}