MainViewController.mm 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // MainViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/5/16.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "MainViewController.h"
  9. #import "DeviceListViewController.h"
  10. #import "AccountViewController.h"
  11. #import "DeviceAddViewController.h"
  12. #import "PhotosViewController.h"
  13. #import "UserAccountModel.h"
  14. #import "APLoginConfigVC.h"
  15. #import "LoginViewController.h"
  16. @interface MainViewController ()<UITableViewDelegate,UITableViewDataSource>
  17. {
  18. UserAccountModel *accountModel;
  19. NSMutableArray *titleArray;
  20. }
  21. //登录状态按钮,如果未登录点击进入登录界面
  22. @property (nonatomic, strong) UIBarButtonItem *loginBtn;
  23. @property (nonatomic, strong) UITableView *mainTableView;
  24. @end
  25. @implementation MainViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. //设置导航栏样式
  29. [self setNaviStyle];
  30. [self initData];
  31. //判断用户登录类型,如果非自动登录需要跳转到登录界面
  32. //if ([LoginShowControl getAutoLoginType] == NO) {
  33. // [self presentToLoginVC];
  34. //}
  35. //配置子试图
  36. [self configSubView];
  37. }
  38. - (void)setNaviStyle {
  39. self.navigationItem.title = TS("FunSDKDemo");
  40. [self.navigationController.navigationBar setBarTintColor:GlobalMainColor];
  41. self.loginBtn = [[UIBarButtonItem alloc] initWithTitle:TS("Logout") style:UIBarButtonItemStyleDone target:self action:@selector(loginOpration)];
  42. self.navigationItem.rightBarButtonItem = self.loginBtn;
  43. self.loginBtn.tintColor = [UIColor whiteColor];
  44. self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
  45. }
  46. - (void)initData {
  47. accountModel = [[UserAccountModel alloc] init];
  48. titleArray = (NSMutableArray*)@[TS("About_User"),TS("About_Device"),TS("DeviceList"),
  49. TS("photos"),TS("About_Demo")];
  50. }
  51. - (void)configSubView {
  52. [self.view addSubview:self.mainTableView];
  53. }
  54. #pragma mark -- UITableViewDelegate/dataSource
  55. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  56. return 50;
  57. }
  58. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  59. return titleArray.count;
  60. }
  61. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  62. return 15;
  63. }
  64. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  65. return 1;
  66. }
  67. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  68. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mainCell"];
  69. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  70. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  71. cell.textLabel.text = [titleArray objectAtIndex:indexPath.section];
  72. return cell;
  73. }
  74. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  75. NSString *title = [titleArray objectAtIndex:indexPath.section];
  76. if ([title isEqualToString:TS("About_User")]) {
  77. //用户信息视图控制器,包括注册,登录,找回密码,修改密码等等
  78. AccountViewController *accountVC = [[AccountViewController alloc] initWithNibName:nil bundle:nil];
  79. [self.navigationController pushViewController:accountVC animated:YES];
  80. }
  81. if ([title isEqualToString:TS("About_Device")]) {
  82. //如果是直连状态,不支持添加设备
  83. if ([[LoginShowControl getInstance] getLoginType] == loginTypeAP) {
  84. APLoginConfigVC *vc = [[APLoginConfigVC alloc] init];
  85. [self.navigationController pushViewController:vc animated:YES];
  86. // UIAlertController *alert = [UIAlertController alertControllerWithTitle:TS("Error_Prompt") message:TS("not_support_add_device") preferredStyle:UIAlertControllerStyleAlert];
  87. // UIAlertAction *okAction = [UIAlertAction actionWithTitle:TS("OK") style:UIAlertActionStyleCancel handler:nil];
  88. // [alert addAction:okAction];
  89. // [self presentViewController:alert animated:YES completion:nil];
  90. return;
  91. }
  92. //添加设备控制器,包括序列号添加设备、IP域名添加设备、Wi-Fi快速配置添加设备、局域网搜索添加设备等
  93. DeviceAddViewController *deviceAddVC = [[DeviceAddViewController alloc] initWithNibName:nil bundle:nil];
  94. [self.navigationController pushViewController:deviceAddVC animated:YES];
  95. }
  96. if ([title isEqualToString:TS("DeviceList")]) {
  97. //设备列表控制器
  98. DeviceListViewController *devicelistVC = [[DeviceListViewController alloc] initWithNibName:nil bundle:nil];
  99. [self.navigationController pushViewController:devicelistVC animated:YES];
  100. }
  101. if ([title isEqualToString:TS("photos")]) {
  102. //本地相册控制器
  103. PhotosViewController *photosVC = [[PhotosViewController alloc] initWithNibName:nil bundle:nil];
  104. [self.navigationController pushViewController:photosVC animated:YES];
  105. }
  106. if ([title isEqualToString:TS("About_Demo")]) {
  107. }
  108. }
  109. #pragma mark -- 未登录或者登出按钮点击
  110. - (void)loginOpration {
  111. //跳转到登陆界面
  112. //Jump to the login interface
  113. if ([[LoginShowControl getInstance] getLoginType] != loginTypeNone) {
  114. [accountModel loginOut];
  115. [[LoginShowControl getInstance] setLoginType:loginTypeNone];
  116. }
  117. [self presentToLoginVC];
  118. }
  119. - (void)presentToLoginVC {
  120. LoginViewController *loginV = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
  121. [self.navigationController pushViewController:loginV animated:YES];
  122. }
  123. - (UITableView *)mainTableView {
  124. if (!_mainTableView) {
  125. _mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 0, ScreenWidth - 20, ScreenHeight) style:UITableViewStylePlain];
  126. _mainTableView.delegate = self;
  127. _mainTableView.dataSource = self;
  128. _mainTableView.estimatedRowHeight = 0;
  129. _mainTableView.estimatedSectionHeaderHeight = 0;
  130. _mainTableView.estimatedSectionFooterHeight = 0;
  131. [_mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"mainCell"];
  132. _mainTableView.tableFooterView = [UIView new];
  133. }
  134. return _mainTableView;
  135. }
  136. @end