Created
July 2, 2015 23:55
-
-
Save mingsai/87b4b7d6e36f01456f8e to your computer and use it in GitHub Desktop.
A delegate class to handle UICollectionView events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MNGCollectionViewHandler.swift | |
// | |
// | |
// Created by Tommie N. Carter, Jr., MBA on 6/21/15. | |
// Copyright © 2015 MING Technology. All rights reserved. | |
// | |
import UIKit | |
class MNGCollectionViewHandler: NSObject, UICollectionViewDelegate, UICollectionViewDataSource { | |
var data:[Photo]? = [] | |
var collectionView:UICollectionView? = nil | |
let flowLayout = UICollectionViewFlowLayout() | |
override init() { | |
super.init() | |
setupCollectionViewFlowLayout() | |
} | |
convenience init (aCollectionView:UICollectionView) { | |
self.init() | |
collectionView = aCollectionView | |
if collectionView != nil { | |
collectionView!.setCollectionViewLayout(self.flowLayout, animated: true) | |
} | |
} | |
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { | |
// | |
return UICollectionViewCell() | |
} | |
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { | |
// | |
} | |
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
//collectionView.setCollectionViewLayout(self.flowLayout, animated: true) | |
return self.data?.count ?? 1 | |
} | |
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { | |
return 1 | |
} | |
func setupCollectionViewFlowLayout () { | |
flowLayout.scrollDirection = .Horizontal | |
flowLayout.minimumInteritemSpacing = 0.0 | |
flowLayout.minimumLineSpacing = 0.0 | |
if self.data?.count > 0 { | |
collectionView!.pagingEnabled = true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment