// // MainViewController.swift // MTP2_iOS // // Created by zhongyuan on 2018/5/19. // Copyright © 2018年 zhongyuan.All rights reserved. // import UIKit import NVActivityIndicatorView import WHToast /// 主窗体 class MainViewController: UITabBarController { // MARK: - 生命周期相关 override func viewDidLoad() { super.viewDidLoad() /// 设置委托代理 self.delegate = self /// 初始化界面 buildView() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) /// 开始查询公告消息数据 MTP2BusinessCore.shared.noticeManager?.startAutoQueryNotices() } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) /// 添加广播通知接受 MTP2BusinessCore.shared.broadcastManager?.addBroadcastListener(owner: self, action: .NoticeChange, block: { (obj) in DispatchQueue.main.async { if let objs = MTP2BusinessCore.shared.noticeManager?.notices.filter({$0.readed == false}), objs.count != 0 { self.viewControllers?[2].tabBarItem.badgeValue = "\(objs.count)" } } }) } override func viewDidDisappear(_ animated: Bool) { super.viewDidAppear(animated) MTP2BusinessCore.shared.broadcastManager?.removeBroadcastListener(owner: self) } // MARK: - 广播通知 // MARK: - 加载配置项功能相关 private func buildView() { /// 设置tabbar背景色 self.tabBar.barTintColor = UIColor.white /// 去掉毛玻璃效果 self.tabBar.isTranslucent = false if let fundations = ConfigUtils.getValue(key: .functionModule) as? [String] { var viewcontrollers = [UIViewController]() for id in fundations { if id == "Home" { /// 首页 let navigationController = UIStoryboard(name: "Home", bundle: nil).instantiateViewController(withIdentifier: "Home") as! BaseNavigationController viewcontrollers.append(navigationController) } else if id == "Mine" { /// 我的页面 let navigationController = UIStoryboard(name: "Mine", bundle: nil).instantiateViewController(withIdentifier: "Mine") as! BaseNavigationController viewcontrollers.append(navigationController) } else if id == "Quote" { /// 行情 let navigationController = UIStoryboard(name: "Quote", bundle: nil).instantiateViewController(withIdentifier: "Quote") as! BaseNavigationController viewcontrollers.append(navigationController) } else if id == "Message" { /// 消息 let navigationController = UIStoryboard(name: "Message", bundle: nil).instantiateViewController(withIdentifier: "Message") as! BaseNavigationController viewcontrollers.append(navigationController) } } self.viewControllers = viewcontrollers } } } extension MainViewController: UITabBarControllerDelegate { func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool { /// 未登录 if let sub = (viewController as? BaseNavigationController)?.viewControllers[0], sub.isKind(of: MessageViewController.self), !MTP2BusinessCore.shared.getLoginStatus() { /// 弹出登录页面 tabBarController.viewControllers?[0].present(storyboardName: "Main", storyboardId: "Login") return false } return true } }