No Description

CreateGroupViewController.swift 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // CreateGroupViewController.swift
  3. // PaiAi
  4. //
  5. // Created by zhengjianfei on 16/4/2.
  6. // Copyright © 2016年 FFIB. All rights reserved.
  7. //
  8. import UIKit
  9. protocol CreateGroupViewControllerDelegate: class {
  10. func didSelect(_ item: GroupItem)
  11. func navigateToCreateGroupConfirm()
  12. }
  13. final class CreateGroupViewController: AlertViewController {
  14. // MARK: Storyboard property
  15. @IBOutlet weak var tableView: UITableView!
  16. @IBOutlet weak var contentView: UIView!
  17. @IBOutlet weak var contentHeightConstraint: NSLayoutConstraint!
  18. weak var delegate: CreateGroupViewControllerDelegate?
  19. override var style: AlertViewController.Style {
  20. return .actionSheet
  21. }
  22. // MARK: view function
  23. override func viewDidLoad() {
  24. super.viewDidLoad()
  25. contentHeightConstraint.constant = 48 + 44 * CGFloat(RecentGroupInfo.share.count + 1)
  26. }
  27. // MARK: Storyboard button function
  28. @IBAction func cancel() {
  29. dismissController()
  30. }
  31. override func getContentView() -> UIView? {
  32. return contentView
  33. }
  34. }
  35. extension CreateGroupViewController: UITableViewDataSource, UITableViewDelegate {
  36. func numberOfSections(in tableView: UITableView) -> Int {
  37. return 1
  38. }
  39. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  40. return RecentGroupInfo.share.count + 1
  41. }
  42. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  43. dismissController()
  44. switch indexPath.row {
  45. case 0:
  46. self.delegate?.navigateToCreateGroupConfirm()
  47. default:
  48. self.delegate?.didSelect(RecentGroupInfo.share[indexPath.row - 1])
  49. }
  50. }
  51. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  52. switch indexPath.row {
  53. case 0:
  54. let cell = tableView.dequeueReusableCell(withIdentifier: "CreateCell", for: indexPath)
  55. return cell
  56. default:
  57. let cell = tableView.dequeueReusableCell(withIdentifier: "RecentCell", for: indexPath)
  58. // let group =
  59. // (cell.viewWithTag(90) as? UILabel).flatMap {$0}?.text = group.group_name
  60. // (cell.viewWithTag(90) as? UIImageView).flatMap {$0}?.setImageWithNullableURL(group.group_avatar, placeholderImage: UIImage(named: "Group\(group.group_default_avatar)"))
  61. return cell
  62. }
  63. }
  64. }