Skip to content

Instantly share code, notes, and snippets.

@mingsai
Created July 2, 2015 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mingsai/87b4b7d6e36f01456f8e to your computer and use it in GitHub Desktop.
Save mingsai/87b4b7d6e36f01456f8e to your computer and use it in GitHub Desktop.
A delegate class to handle UICollectionView events
//
// 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