OOSelectPersonTableViewCell.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // OOSelectPersonTableViewCell.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2018/5/4.
  6. // Copyright © 2018年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. class OOSelectPersonTableViewCell: UITableViewCell,Configurable {
  10. @IBOutlet weak var personCollectionView: UICollectionView!
  11. private var models:[OOPersonModel] = []
  12. override func awakeFromNib() {
  13. super.awakeFromNib()
  14. personCollectionView.register(UINib.init(nibName: "OOPersonCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "personItemCell")
  15. personCollectionView.dataSource = self
  16. personCollectionView.delegate = self
  17. }
  18. override func setSelected(_ selected: Bool, animated: Bool) {
  19. super.setSelected(selected, animated: animated)
  20. // Configure the view for the selected state
  21. }
  22. func config(withItem item: Any?) {
  23. guard let items = item as? [OOPersonModel] else {
  24. return
  25. }
  26. models = items
  27. personCollectionView.reloadData()
  28. }
  29. }
  30. extension OOSelectPersonTableViewCell:UICollectionViewDelegate,UICollectionViewDataSource {
  31. func numberOfSections(in collectionView: UICollectionView) -> Int {
  32. return 1
  33. }
  34. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  35. return models.count
  36. }
  37. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  38. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "personItemCell", for: indexPath) as! (OOPersonCollectionViewCell & Configurable)
  39. cell.config(withItem: models[indexPath.row])
  40. return cell
  41. }
  42. }