RDSHomeListVC.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // RDSHomeListVC.m
  3. // Temperature
  4. //
  5. // Created by RD on 2022/12/3.
  6. //
  7. #import "RDSHomeListVC.h"
  8. #import "RDSHomeListCell.h"
  9. #import "RDSHomeModel.h"
  10. #import "RDSAddHomeVC.h"
  11. #import "RDSHomeInfoVC.h"
  12. #import <MJRefresh/MJRefresh.h>
  13. static NSString * const RDSHomeListCellID = @"RDSHomeListCell";
  14. @interface RDSHomeListVC ()<UITableViewDelegate , UITableViewDataSource>
  15. @property (nonatomic, weak) UITableView *tableView;
  16. @end
  17. @implementation RDSHomeListVC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. self.title = @"家庭管理";
  22. [self p_navItem];
  23. [self p_setupTableView];
  24. }
  25. - (void)viewWillAppear:(BOOL)animated{
  26. [super viewWillAppear:animated];
  27. [self p_getHomeList];
  28. }
  29. - (void)p_navItem{
  30. UIBarButtonItem *item = [RDSBarButtonItem barButtonItemWithTitle:@"新建" color:kTextColor target:self action:@selector(p_onAddItem)];
  31. [self.navigationItem setRightBarButtonItem:item];
  32. }
  33. - (void)p_onAddItem{
  34. RDSAddHomeVC *vc = [[RDSAddHomeVC alloc] init];
  35. [self pushViewController:vc animated:YES];
  36. }
  37. - (void)p_getHomeList{
  38. RDS_WEAKSELF(weakSelf)
  39. [RDSHomeModel rds_getHomeListIsAdmin:YES finished:^(NSError * _Nonnull error) {
  40. [weakSelf.tableView.mj_header endRefreshing];
  41. [weakSelf.tableView reloadData];
  42. }];
  43. }
  44. - (void)p_setupTableView {
  45. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, SCREEN_HEIGHT-20-60)];
  46. [self.view addSubview:tableView];
  47. tableView.dataSource = self;
  48. tableView.delegate = self;
  49. tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
  50. self.tableView = tableView;
  51. self.tableView.backgroundColor = [UIColor clearColor];
  52. [self.tableView registerNib:[UINib nibWithNibName:@"RDSHomeListCell" bundle:nil] forCellReuseIdentifier:RDSHomeListCellID];
  53. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  54. self.tableView.showsVerticalScrollIndicator = NO;
  55. tableView.rowHeight = 100*kSCALE_WIDTH_X;
  56. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(p_getHomeList)];
  57. header.automaticallyChangeAlpha = YES;
  58. header.lastUpdatedTimeLabel.hidden = YES;
  59. self.tableView.mj_header = header;
  60. }
  61. #pragma mark - Table view data source
  62. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  63. return TheDataManager.homesAdmin.count;
  64. }
  65. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  66. RDSHomeListCell *cell = [tableView dequeueReusableCellWithIdentifier:RDSHomeListCellID];
  67. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  68. cell.model = TheDataManager.homesAdmin[indexPath.row];
  69. return cell;
  70. }
  71. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  72. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  73. RDSHomeInfoVC *vc = [[RDSHomeInfoVC alloc] init];
  74. vc.home = TheDataManager.homesAdmin[indexPath.row];
  75. [self pushViewController:vc animated:YES];
  76. }
  77. - (void)dealloc{
  78. DDLog(@"dealloc");
  79. }
  80. @end