Last active
August 29, 2015 14:26
-
-
Save donnywals/45041430e030ef17c88e to your computer and use it in GitHub Desktop.
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 characters
class MainViewController: UIViewController() { | |
var viewModel = WebsiteList() | |
func tabsButtonPressed() { | |
let vc = ListView(vm: viewModel) | |
// present the vc | |
} | |
} | |
class ListView: UIViewController { | |
var viewModel: WebsiteList | |
@IBOutlet collectionView: UICollectionView! | |
convenience init(vm: WebsiteList) { | |
viewModel = vm | |
} | |
override func viewDidLoad() { | |
collectionView.dataSource = self | |
} | |
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { | |
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("myCell", forIndexPath: indexPath) as! MyCell | |
cell.image = viewModel.imageForIndexPath(indexPath) | |
return cell | |
} | |
} | |
struct WebsiteList { | |
var images: [UIImage] = [UIImage]() | |
func addImage(image: UIImage) { | |
images.append(image) | |
} | |
func imageForIndexPath(indexPath: NSIndexPath) -> UIImage { | |
return images[indexPath.row] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment