WFCUDomainTableViewController.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // FavGroupTableViewController.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/13.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUDomainTableViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "WFCUDomainProfileTableViewController.h"
  11. #import "UIView+Toast.h"
  12. #import "WFCUImage.h"
  13. @interface WFCUDomainTableViewController ()
  14. @property (nonatomic, strong)NSArray<WFCCDomainInfo *> *domains;
  15. @end
  16. @implementation WFCUDomainTableViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.domains = [[NSMutableArray alloc] init];
  20. self.title = WFCString(@"Mesh");
  21. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  22. if(self.isPresent) {
  23. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:self action:@selector(onClose:)];
  24. }
  25. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSettingUpdated:) name:kSettingUpdated object:nil];
  26. }
  27. - (void)onSettingUpdated:(NSNotification *)notification {
  28. [self refreshList];
  29. }
  30. - (void)onClose:(id)sender {
  31. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  32. }
  33. - (void)refreshList {
  34. __weak typeof(self)ws = self;
  35. [[WFCCIMService sharedWFCIMService] getRemoteDomains:^(NSArray<WFCCDomainInfo *> *domains) {
  36. ws.domains = domains;
  37. [ws.tableView reloadData];
  38. } error:^(int errorCode) {
  39. [ws.view makeToast:@"网络错误"];
  40. }];
  41. }
  42. - (void)viewWillAppear:(BOOL)animated {
  43. [super viewWillAppear:animated];
  44. [self refreshList];
  45. self.tabBarController.tabBar.hidden = YES;
  46. }
  47. - (void)didReceiveMemoryWarning {
  48. [super didReceiveMemoryWarning];
  49. // Dispose of any resources that can be recreated.
  50. }
  51. #pragma mark - Table view data source
  52. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  53. return 1;
  54. }
  55. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  56. return self.domains.count;
  57. }
  58. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  59. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"groupCellId"];
  60. if (cell == nil) {
  61. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"groupCellId"];
  62. cell.imageView.image = [WFCUImage imageNamed:@"organization_icon"];
  63. }
  64. cell.textLabel.text = self.domains[indexPath.row].name;
  65. return cell;
  66. }
  67. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  68. if(self.onSelect) {
  69. self.onSelect(self.domains[indexPath.row].domainId);
  70. if(self.isPresent) {
  71. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  72. } else {
  73. [self.navigationController popViewControllerAnimated:YES];
  74. }
  75. } else {
  76. WFCUDomainProfileTableViewController *vc = [[WFCUDomainProfileTableViewController alloc] init];
  77. vc.domainId = self.domains[indexPath.row].domainId;
  78. [self.navigationController pushViewController:vc animated:YES];
  79. }
  80. }
  81. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  82. return 56;
  83. }
  84. - (void)dealloc {
  85. [[NSNotificationCenter defaultCenter] removeObserver:self];
  86. }
  87. @end