OOTabBarController.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // OOTabBarController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2018/4/12.
  6. // Copyright © 2018年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CYLTabBarController
  10. import CocoaLumberjack
  11. class OOTabBarController: CYLTabBarController,UITabBarControllerDelegate {
  12. static var tabBarVC:OOTabBarController!
  13. private var currentIndex:Int = 0
  14. private let viewModel:OOLoginViewModel = {
  15. return OOLoginViewModel()
  16. }()
  17. override func viewDidLoad() {
  18. super.viewDidLoad()
  19. self.delegate = self
  20. selectedIndex = 2
  21. currentIndex = 2
  22. _init()
  23. }
  24. private func _init() {
  25. viewModel.registerIM().then { (result) in
  26. self.viewModel.loginIM().then({ (result) in
  27. Log.debug(message: "IM登陆完成")
  28. })
  29. }.catch { (imError) in
  30. let error = imError as! OOLoginError
  31. switch error {
  32. case .imRegisterFail(let myErr):
  33. Log.debug(message: myErr.errorDescription!)
  34. self.viewModel.loginIM().then({ (result) in
  35. Log.debug(message: "IM登陆完成")
  36. }).catch({ (loginError) in
  37. Log.error(message: "im Login Error \(loginError)")
  38. })
  39. break
  40. default:
  41. break
  42. }
  43. }
  44. }
  45. static func genernateVC(viewControllers:[UIViewController],tabBarItemsAttributes:[[String : String]]) -> OOTabBarController {
  46. guard let myVC = tabBarVC else {
  47. tabBarVC = OOTabBarController(viewControllers: viewControllers, tabBarItemsAttributes: tabBarItemsAttributes)
  48. return tabBarVC
  49. }
  50. return myVC
  51. }
  52. static func genernateVC() -> OOTabBarController {
  53. guard let myVC = tabBarVC else {
  54. tabBarVC = OOTabBarController(viewControllers: OOTabBarHelper.viewControllers(), tabBarItemsAttributes: OOTabBarHelper.tabBarItemsAttributesForController())
  55. return tabBarVC
  56. }
  57. return myVC
  58. }
  59. func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
  60. self.cyl_tabBarController.updateSelectionStatusIfNeeded(for: tabBarController, shouldSelect: viewController)
  61. return true
  62. }
  63. override func tabBarController(_ tabBarController: UITabBarController!, didSelect control: UIControl!) {
  64. if control is CYLPlusButton {
  65. if currentIndex == 2 && tabBarController.selectedIndex == 2 {
  66. if tabBarController.selectedViewController is ZLNavigationController {
  67. (tabBarController.selectedViewController as! ZLNavigationController).viewControllers.forEach { (vc) in
  68. if vc is MailViewController {
  69. DDLogDebug("点击了首页 portal")
  70. (vc as! MailViewController).loadDetailSubject()
  71. }
  72. if vc is MainTaskSecondViewController {
  73. DDLogDebug("点击了首页index")
  74. }
  75. }
  76. }
  77. }
  78. }
  79. self.currentIndex = tabBarController.selectedIndex
  80. }
  81. }