mikelily

collectionView's cell setting

Oct 23rd, 2018
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.48 KB | None | 0 0
  1. class ViewController: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
  2.  
  3.     let cellId: String = "cellId"
  4.    
  5.     struct cameraInfo {
  6.         var name: String
  7.         var url: String
  8.     }
  9.    
  10.     var cameraList: [cameraInfo] = []
  11.    
  12.     override func viewDidLoad() {
  13.         super.viewDidLoad()
  14.         setupCollectionView()
  15.        
  16.         let canSeeChannel = ["01", "02", "03", "04", "07", "11", "15", "16", "17", "18", "19", "20"]
  17.         for i in 0...11 {
  18.             cameraList.append(cameraInfo(name: "A\(i+1)", url: "http://61.216.177.73/sta/ch18650\(canSeeChannel[i]).m3u8"))
  19.         }
  20.     }
  21.  
  22.     var num: Int = 1
  23.     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  24.         let cell: CameraCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! CameraCollectionViewCell
  25.        
  26.         cell.camera = nil
  27.         print("\n第\(num)次呼叫")
  28.         num = num + 1
  29.         print("indexPath.item:\(indexPath.item)")
  30.         print(cell.camera) 
  31.        
  32.         cell.camera = Camera(name: cameraList[indexPath.item].name, isConnected: true, isLive: true, url: cameraList[indexPath.item].url)
  33.        
  34.         print("After setting")
  35.         print(cell.camera.name)
  36.        
  37.         cell.setupPlayer()
  38.        
  39.        
  40.        
  41.         cell.backgroundColor = .black
  42.        
  43.         return cell
  44.     }
  45.    
  46. }
Advertisement
Add Comment
Please, Sign In to add comment