GroupListController.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // GroupListController.m
  3. // AIIM
  4. //
  5. // Created by gan on 2025/4/6.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "GroupListController.h"
  9. #import "GroupNetApi.h"
  10. #import "GroupListCell.h"
  11. #import "GroupController.h"
  12. #import "NewGroupController.h"
  13. @interface GroupListController()<UITableViewDelegate,UITableViewDataSource>
  14. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  15. @property (weak, nonatomic) IBOutlet UILabel *titleLb;
  16. @end
  17. @implementation GroupListController
  18. -(void)viewDidLoad{
  19. [super viewDidLoad];
  20. _titleLb.text = NSLocalizedString(@"TabBarItem3", @"");
  21. [self initSubView];
  22. }
  23. -(void)viewWillAppear:(BOOL)animated{
  24. [super viewWillAppear:YES];
  25. [self getGrouplistData];
  26. // 获取TabBarController
  27. UITabBarController *tabBarController = (UITabBarController *)self.parentViewController;
  28. // 移除红点(使用系统方法)
  29. tabBarController.tabBar.items[2].badgeValue = nil;
  30. }
  31. -(void)initSubView{
  32. _tableView.delegate = self;
  33. _tableView.dataSource = self;
  34. _tableView.backgroundColor = [UIColor clearColor];
  35. [_tableView registerClass:[GroupListCell class] forCellReuseIdentifier:@"group"]; // 使用 Storyboard 时不需要这行代码,除非你混合使用 Storyboard 和代码配置 Cell。
  36. }
  37. -(void)getGrouplistData{
  38. [GroupNetApi getGroupList:^(int code, NSDictionary * res) {
  39. NSLog(@"getGrouplistData res:%@",res);
  40. NSNumber *codeD = res[@"code"];
  41. if([codeD intValue]==401){
  42. [[NSNotificationCenter defaultCenter] postNotificationName: nkonLogoutSucc object:nil];
  43. return;
  44. }
  45. self.grouplist = res[@"data"];
  46. [self.tableView reloadData];
  47. } fail:^(NSError * _Nonnull error) {
  48. NSLog(@"error");
  49. }];
  50. }
  51. - (IBAction)addNewGroup:(id)sender {
  52. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  53. NewGroupController *groupctr = [board instantiateViewControllerWithIdentifier:@"NewGroupController"];
  54. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:groupctr];
  55. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  56. [self presentViewController :uiNavC animated:YES completion:nil];
  57. }
  58. #pragma mark UITableViewDelegate
  59. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  60. return 1;
  61. }
  62. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  63. // NSLog(@"numberOfRowsInSection:%lu",(unsigned long)self.grouplist.count);
  64. return self.grouplist.count;
  65. }
  66. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  67. NSDictionary *data=self.grouplist[indexPath.row];
  68. // NSLog(@"cellForRowAtIndexPath:%@",data);
  69. if(data){
  70. GroupListCell *cell =[tableView dequeueReusableCellWithIdentifier:@"group" forIndexPath:indexPath];
  71. if(cell==nil){
  72. cell=[[GroupListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"group"];
  73. }
  74. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  75. cell.backgroundColor = [UIColor clearColor];
  76. [cell fillWithData:data cellType:0];
  77. return cell;
  78. }
  79. return nil;
  80. }
  81. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  82. return 70;
  83. }
  84. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  85. // NSLog(@"didSelectRowAtIndexPath:%@",indexPath);
  86. NSDictionary *data=self.grouplist[indexPath.row];
  87. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  88. GroupController *groupctr = [board instantiateViewControllerWithIdentifier:@"GroupController"];
  89. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:groupctr];
  90. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  91. groupctr.groupMsg = data;
  92. groupctr.groupId = data[@"id"];
  93. [self presentViewController :uiNavC animated:YES completion:nil];
  94. }
  95. #pragma mark statusBar
  96. - (UIStatusBarStyle)preferredStatusBarStyle{
  97. return UIStatusBarStyleLightContent;
  98. }
  99. @end