Guest User

Untitled

a guest
May 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import UIKit
  2.  
  3. private let reuseIdentifier = "cell"
  4.  
  5. class TVCollectionViewController: UICollectionViewController {
  6.  
  7. override func viewDidLoad() {
  8. super.viewDidLoad()
  9. self.clearsSelectionOnViewWillAppear = false
  10. }
  11.  
  12. override func didReceiveMemoryWarning() {
  13. super.didReceiveMemoryWarning()
  14. }
  15.  
  16. // MARK: UICollectionViewDataSource
  17.  
  18. override func numberOfSections(in collectionView: UICollectionView) -> Int {
  19. return 1
  20. }
  21.  
  22. override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  23. return 3
  24. }
  25.  
  26. override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  27. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! TVCollectionViewCell
  28. cell.displayImage.image = UIImage.init(named: "image" + (indexPath.row+1).description)
  29. return cell
  30. }
  31.  
  32. // MARK: UICollectionViewDelegate
  33.  
  34. override func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool {
  35. return true
  36. }
  37.  
  38. override func collectionView(_ collectionView: UICollectionView, canFocusItemAt indexPath: IndexPath) -> Bool {
  39. return true
  40. }
  41.  
  42. override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  43. print(indexPath.row.description)
  44. }
  45.  
  46.  
  47. }
Add Comment
Please, Sign In to add comment