Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- private let reuseIdentifier = "cell"
- class TVCollectionViewController: UICollectionViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- self.clearsSelectionOnViewWillAppear = false
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- }
- // MARK: UICollectionViewDataSource
- override func numberOfSections(in collectionView: UICollectionView) -> Int {
- return 1
- }
- override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return 3
- }
- override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! TVCollectionViewCell
- cell.displayImage.image = UIImage.init(named: "image" + (indexPath.row+1).description)
- return cell
- }
- // MARK: UICollectionViewDelegate
- override func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool {
- return true
- }
- override func collectionView(_ collectionView: UICollectionView, canFocusItemAt indexPath: IndexPath) -> Bool {
- return true
- }
- override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- print(indexPath.row.description)
- }
- }
Add Comment
Please, Sign In to add comment