Created
August 7, 2017 15:09
-
-
Save loucimj/90fa650fe353ec0f9e225c819bd9186e to your computer and use it in GitHub Desktop.
SectionController using DiffableBox
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
// | |
// TicketSectionController.swift | |
// | |
// Created by Javier Loucim on 8/5/17. | |
// Copyright © 2017 Javier Loucim. All rights reserved. | |
// | |
import Foundation | |
import UIKit | |
import IGListKit | |
protocol TicketSectionControllerDelegate { | |
func ticketWasSelected(ticket:TicketShort) | |
} | |
class TicketSectionController: ListSectionController { | |
convenience init(delegate: TicketSectionControllerDelegate) { | |
self.init() | |
self.delegate = delegate | |
} | |
var data:TicketShort = TicketShort() | |
var delegate:TicketSectionControllerDelegate? | |
override func sizeForItem(at index: Int) -> CGSize { | |
let width = collectionContext!.containerSize.width | |
let height = TicketCollectionViewCell.calculateHeight() | |
return CGSize(width: width, height: height) | |
} | |
override func cellForItem(at index: Int) -> UICollectionViewCell { | |
let cell = collectionContext!.dequeueReusableCell(withNibName: "TicketCollectionViewCell", bundle: Bundle.main, for: self, at: index) as! TicketCollectionViewCell | |
cell.configure(with: data) | |
return cell | |
} | |
override func didUpdate(to object: Any) { | |
let boxed = object as! DiffableBox<TicketShort> | |
self.data = boxed.value | |
} | |
override func didSelectItem(at index: Int) { | |
delegate?.ticketWasSelected(ticket: self.data) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment