GroupListController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. }
  27. -(void)initSubView{
  28. _tableView.delegate = self;
  29. _tableView.dataSource = self;
  30. _tableView.backgroundColor = [UIColor clearColor];
  31. [_tableView registerClass:[GroupListCell class] forCellReuseIdentifier:@"group"]; // 使用 Storyboard 时不需要这行代码,除非你混合使用 Storyboard 和代码配置 Cell。
  32. }
  33. -(void)getGrouplistData{
  34. [GroupNetApi getGroupList:^(int code, NSDictionary * res) {
  35. NSLog(@"getGrouplistData res:%@",res);
  36. NSNumber *codeD = res[@"code"];
  37. if([codeD intValue]==401){
  38. [[NSNotificationCenter defaultCenter] postNotificationName: nkonLogoutSucc object:nil];
  39. return;
  40. }
  41. self.grouplist = res[@"data"];
  42. [self.tableView reloadData];
  43. } fail:^(NSError * _Nonnull error) {
  44. NSLog(@"error");
  45. }];
  46. }
  47. - (IBAction)addNewGroup:(id)sender {
  48. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  49. NewGroupController *groupctr = [board instantiateViewControllerWithIdentifier:@"NewGroupController"];
  50. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:groupctr];
  51. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  52. [self presentViewController :uiNavC animated:YES completion:nil];
  53. }
  54. #pragma mark UITableViewDelegate
  55. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  56. return 1;
  57. }
  58. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  59. // NSLog(@"numberOfRowsInSection:%lu",(unsigned long)self.grouplist.count);
  60. return self.grouplist.count;
  61. }
  62. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  63. NSDictionary *data=self.grouplist[indexPath.row];
  64. // NSLog(@"cellForRowAtIndexPath:%@",data);
  65. if(data){
  66. GroupListCell *cell =[tableView dequeueReusableCellWithIdentifier:@"group" forIndexPath:indexPath];
  67. if(cell==nil){
  68. cell=[[GroupListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"group"];
  69. }
  70. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  71. cell.backgroundColor = [UIColor clearColor];
  72. [cell fillWithData:data cellType:0];
  73. return cell;
  74. }
  75. return nil;
  76. }
  77. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  78. return 70;
  79. }
  80. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  81. // NSLog(@"didSelectRowAtIndexPath:%@",indexPath);
  82. NSDictionary *data=self.grouplist[indexPath.row];
  83. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  84. GroupController *groupctr = [board instantiateViewControllerWithIdentifier:@"GroupController"];
  85. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:groupctr];
  86. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  87. groupctr.groupMsg = data;
  88. groupctr.groupId = data[@"id"];
  89. [self presentViewController :uiNavC animated:YES completion:nil];
  90. }
  91. #pragma mark statusBar
  92. - (UIStatusBarStyle)preferredStatusBarStyle{
  93. return UIStatusBarStyleLightContent;
  94. }
  95. @end