ImageCheckRow.swift 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // ImageCheckRow.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2016/10/2.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import Foundation
  9. import Eureka
  10. public final class ImageCheckRow<T: Equatable>: Row<ImageCheckCell<T>>, SelectableRowType, RowType {
  11. public var selectableValue: T?
  12. required public init(tag: String?) {
  13. super.init(tag: tag)
  14. displayValueFor = nil
  15. }
  16. }
  17. public class ImageCheckCell<T: Equatable> : Cell<T>, CellType {
  18. required public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  19. super.init(style: style, reuseIdentifier: reuseIdentifier)
  20. }
  21. required public init?(coder aDecoder: NSCoder) {
  22. fatalError("init(coder:) has not been implemented")
  23. }
  24. lazy public var trueImage: UIImage = {
  25. return UIImage(named: "selected")!
  26. }()
  27. lazy public var falseImage: UIImage = {
  28. return UIImage(named: "unselected")!
  29. }()
  30. public override func update() {
  31. super.update()
  32. accessoryType = .none
  33. imageView?.image = row.value != nil ? trueImage : falseImage
  34. }
  35. public override func setup() {
  36. super.setup()
  37. }
  38. public override func didSelect() {
  39. row.reload()
  40. row.select()
  41. row.deselect()
  42. }
  43. }