Y
Y
YeahCode2020-05-08 16:46:36
Arrays
YeahCode, 2020-05-08 16:46:36

Show photo/video from array in collectionview, scrollview?

Guys, tell
me 1. There is an array where image and video are mixed. What is the best way to identify which URL is which. Since photos and videos are in discord
2. Requires horizontal scrolling. What is the best way to display this? In collectionview, scrollview or other options?
3. While taking a photo or video through enum and switch, or are there other adequate options?
4. I would be grateful for any hint, because the network has options only for video or only for photos

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "DefaultCell", for: indexPath) as? SlideShowCollectionViewCell else { fatalError("\nSlide Show Error Cell\n") }
            
            var urlType = [CellType]()
            let urlArray = urlType[indexPath.row]
            
            switch urlArray {
            case .image(var url):
                url = images[indexPath.row]
                cell.imageView.sd_setImage(with: url)
            case .video(let url):
                cell.videoView.addSubview(playerView)
                addPlayer(for: url)
            }
       }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
briahas, 2020-05-08
@briahas

1. if you need to define an action when you click on a cell, then
- by the index of the clicked cell, you get the model from urlType and here's the type for you
2. collectionview
3. there are a lot of them.

  • it is possible as in your example - through enam
  • different models are possible, but satisfying the same protocol (by which you can get the type and url)
  • you can, in addition to the previous ones, also cells of different types (instead of one type, but with two views imageView and videoView), and understand them
  • ... or you can generally "crutches" and "trash" to fence whatever your heart desires

4. It is not clear what are the business requirements for this collectionview ( read: what will it need to do? )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question