RootViewController.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // RootViewController.m
  3. // Apex Mobile
  4. //
  5. // Created by Ray on 25/01/2018.
  6. // Copyright © 2018 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RootViewController.h"
  9. @interface RootViewController ()
  10. @end
  11. @implementation RootViewController
  12. - (UITabBarItem *)itemWithSelectedImage:(NSString *)selectImage image:(NSString *)image title:(NSString *)title{
  13. UIImage *im = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  14. UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:title image:im selectedImage:im];
  15. return item;
  16. }
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. [self registForNotification];
  20. self.automaticallyAdjustsScrollViewInsets = NO;
  21. // self.navigationItem.navi
  22. // [self.navigationController setNavigationBarHidden:YES animated:YES];
  23. // [UIStoryboard storyboardWithName:@"EnumSelectAndSort" bundle:nil]
  24. UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
  25. backItem.title = @"Back";
  26. self.navigationItem.backBarButtonItem = backItem;
  27. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  28. LoginViewController * loginVC = [ [UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginPanel"];
  29. loginVC.loginSuccessful = ^(void)
  30. {
  31. appDelegate.isLogin = YES;
  32. appDelegate.shouldCheckCache = YES;
  33. // 登陆成功后重新刷新tabbar
  34. self.viewControllers = self.loginbar;
  35. };
  36. // loginVC.tabBarItem = [self itemWithSelectedImage:@"login" image:@"login" title:@"login"];
  37. // ToolslistViewController* toolVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ToolsPanel"];
  38. ToolslistViewController *toolVC=[[ToolslistViewController alloc] initWithNibName:@"StaticModelistViewController" bundle:nil];
  39. HomeViewController* homeVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"HomePanel"];
  40. SearchlistViewController* searchVC = [[SearchlistViewController alloc] initWithNibName:@"StaticModelistViewController" bundle:nil];
  41. //[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"SearchPanel"];
  42. MylistViewController* myVC = [[MylistViewController alloc] initWithNibName:@"StaticModelistViewController" bundle:nil];
  43. myVC.logoutSuccessful = ^(void)
  44. {
  45. appDelegate.isLogin = NO;
  46. // 登陆成功后重新刷新tabbar
  47. self.viewControllers = self.logoutbar;
  48. };
  49. //[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"MyPanel"];
  50. OrderHistoryViewController* historyVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"HistoryPanel"];
  51. // toolVC.tabBarItem = [self itemWithSelectedImage:@"tools" image:@"tools" title:@"tools"];
  52. // Do any additional setup after loading the view.
  53. self.logoutbar = @[loginVC,toolVC];
  54. self.loginbar = @[homeVC,historyVC,searchVC,toolVC,myVC];
  55. self.viewControllers = self.logoutbar;
  56. // tabbar 选中色
  57. self.tabBar.tintColor = [UIColor colorWithRed:168 / 255.0 green:9 / 255.0 blue:26 / 255.0 alpha:1.0];
  58. // self.tabBar.tintColor = [UIColor blueColor];
  59. // self.tabBar.barTintColor = [UIColor blackColor];
  60. }
  61. - (void)didReceiveMemoryWarning {
  62. [super didReceiveMemoryWarning];
  63. // Dispose of any resources that can be recreated.
  64. }
  65. /*
  66. #pragma mark - Navigation
  67. // In a storyboard-based application, you will often want to do a little preparation before navigation
  68. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  69. // Get the new view controller using [segue destinationViewController].
  70. // Pass the selected object to the new view controller.
  71. }
  72. */
  73. - (void)dealloc {
  74. [[NSNotificationCenter defaultCenter] removeObserver:self];
  75. }
  76. - (void)registForNotification {
  77. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:NotificationTypeLogout object:nil];
  78. }
  79. - (void)handleNotification:(NSNotification *)notification {
  80. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  81. if ([notification.name isEqualToString:NotificationTypeLogout]) {
  82. [appDelegate Logout];
  83. [(LoginViewController *)self.logoutbar.firstObject clear];
  84. self.viewControllers = self.logoutbar;
  85. self.selectedIndex = 0;
  86. }
  87. }
  88. @end