Last active
December 27, 2018 16:38
Revisions
-
lostincode revised this gist
Oct 15, 2014 . 1 changed file with 16 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,17 @@ // // CustomUICollectionViewCell.swift // // Created by Bill Richards on 9/24/14. // Copyright (c) 2014 Bill Richards. All rights reserved. // import UIKit class CustomUICollectionViewCell: UICollectionViewCell { //Example cell configuration func configureForItem(item:AnyObject) { //do something with the cell... } } -
lostincode revised this gist
Oct 15, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -15,8 +15,8 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() //Init our datasource and setup the closure to handle our cell //modify 'AnyObject' to match your model self.dataSource = CollectionViewDataSource(items: self.items, cellIdentifier: "Cell", configureBlock: { (cell, item) -> () in if let actualCell = cell as? CustomUICollectionViewCell { if let actualItem = item as? AnyObject { -
lostincode revised this gist
Oct 15, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import UIKit class ViewController: UIViewController { //variable to hold reference to the datasource var dataSource:CollectionViewDataSource? -
lostincode revised this gist
Oct 15, 2014 . 1 changed file with 31 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,33 @@ // // ViewController.swift // // Created by Bill Richards on 10/7/14. // Copyright (c) 2014 Bill Richards. All rights reserved. // import UIKit class ViewController: UITableViewController { //variable to hold reference to the datasource var dataSource:CollectionViewDataSource? override func viewDidLoad() { super.viewDidLoad() //setup the closure to handle our cell //modify AnyObject to match your model self.dataSource = CollectionViewDataSource(items: self.items, cellIdentifier: "Cell", configureBlock: { (cell, item) -> () in if let actualCell = cell as? CustomUICollectionViewCell { if let actualItem = item as? AnyObject { actualCell.configureForItem(actualItem) } } }) //finally, set the collectionview datasource self.collectionView.dataSource = self.dataSource } } -
lostincode revised this gist
Oct 15, 2014 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ //variable to hold reference to the datasource var dataSource:CollectionViewDataSource? -
lostincode revised this gist
Oct 15, 2014 . 3 changed files with 21 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ //Example cell configuration func configureForItem(item:AnyObject) { //do something with the cell... } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ /*ViewController usage*/ //variable to hold reference to the datasource var dataSource:CollectionViewDataSource? //setup the closure to handle our cell //modify AnyObject to match your model self.dataSource = CollectionViewDataSource(items: self.items, cellIdentifier: "Cell", configureBlock: { (cell, item) -> () in if let actualCell = cell as? CustomUICollectionViewCell { if let actualItem = item as? AnyObject { actualCell.configureForItem(actualItem) } } }) //finally, set the collectionview datasource self.collectionView.dataSource = self.dataSource -
lostincode created this gist
Oct 15, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ // // CollectionViewDataSource.swift // // Created by Bill Richards on 10/1/14. // Copyright (c) 2014 Bill Richards. All rights reserved. // import Foundation typealias CollectionViewCellConfigureBlock = (cell:UICollectionViewCell, item:AnyObject?) -> () class CollectionViewDataSource: NSObject, UICollectionViewDataSource { var items:NSArray = [] var itemIdentifier:String? var configureCellBlock:CollectionViewCellConfigureBlock? init(items: NSArray, cellIdentifier: String, configureBlock: CollectionViewCellConfigureBlock) { self.items = items self.itemIdentifier = cellIdentifier self.configureCellBlock = configureBlock super.init() } func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return items.count } func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier(self.itemIdentifier!, forIndexPath: indexPath) as UICollectionViewCell let item: AnyObject = self.itemAtIndexPath(indexPath) if (self.configureCellBlock != nil) { self.configureCellBlock!(cell: cell, item: item) } return cell } func itemAtIndexPath(indexPath: NSIndexPath) -> AnyObject { return self.items[indexPath.row] } }