XYMedalListViewController.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // XYMedalListViewController.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/1/13.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYMedalListViewController.h"
  9. #import "XYMedalListViewModel.h"
  10. #import "XYMedalListTableViewCell.h"
  11. #import "XYMedalListCellModel.h"
  12. @interface XYMedalListViewController ()<XYMedalListTableViewCellDelegate>
  13. @property (nonatomic, readwrite, strong) XYMedalListViewModel *viewModel;
  14. @end
  15. @implementation XYMedalListViewController
  16. - (void)dealloc {
  17. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"Refresh_Mount_listNotification" object:nil];
  18. }
  19. /// 重写init方法,配置你想要的属性
  20. - (instancetype)init
  21. {
  22. self = [super init];
  23. if (self) {
  24. self.prefersNavigationBarBottomLineHidden = YES;
  25. }
  26. return self;
  27. }
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. /// 设置
  31. [self _setup];
  32. /// 设置导航栏
  33. [self _setupNavigationItem];
  34. /// 设置子控件
  35. [self _setupSubViews];
  36. /// 布局子空间
  37. [self _makeSubViewsConstraints];
  38. [self tableViewDidTriggerHeaderRefresh];
  39. // 使用坐骑卡后刷新坐骑列表
  40. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tableViewDidTriggerHeaderRefresh) name:@"Refresh_Mount_listNotification" object:nil];
  41. }
  42. #pragma mark — Override
  43. - (void)bindViewModel {
  44. self.viewModel = [XYMedalListViewModel new];
  45. }
  46. - (UIEdgeInsets)contentInset {
  47. return UIEdgeInsetsMake(0, 0, NAVGATION_HEIGHT + 44.0f, 0);
  48. }
  49. - (void)tableViewDidTriggerHeaderRefresh {
  50. self.viewModel.pullDown = YES;
  51. [self.viewModel loadData:^(id responseModel) {
  52. [self tableViewDidFinishTriggerHeader:YES reload:YES];
  53. [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:kLocalizedString(@"背包空空~心脏痛痛~") errorInfo:@"" offsetTop:200.0f hasData:self.viewModel.dataSource.count>0 hasError:NO reloadBlock:nil];
  54. } failure:^(NSError *error) {
  55. [self tableViewDidFinishTriggerHeader:YES reload:YES];
  56. [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:kLocalizedString(@"背包空空~心脏痛痛~") errorInfo:error.domain offsetTop:200.0f hasData:self.viewModel.dataSource.count>0 hasError:error!=nil reloadBlock:nil];
  57. }];
  58. }
  59. - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  60. return [XYMedalListTableViewCell cellWithTableView:tableView];
  61. }
  62. - (void)configureCell:(XYMedalListTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  63. [cell configureModel:object];
  64. [cell setIndexPath:indexPath rowsInSection:self.viewModel.dataSource.count-1];
  65. cell.delegate = self;
  66. }
  67. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  68. return 120.0f;
  69. }
  70. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  71. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  72. }
  73. #pragma mark — XYMedalListTableViewCellDelegate
  74. - (void)swichViewDidDelayChange:(BOOL)on atIndexPath:(NSIndexPath *)indexPath {
  75. [self.viewModel selectedMedalWithIndex:indexPath.row success:^(id _Nullable responseModel) {
  76. [self tableViewDidFinishTriggerHeader:YES reload:YES];
  77. } failure:^(ZYLNetworkError * _Nullable error) {
  78. [SVProgressHUD showInfoWithStatus:error.domain];
  79. }];
  80. }
  81. #pragma mark - 事件处理Or辅助方法
  82. #pragma mark - 初始化
  83. - (void)_setup{
  84. self.tableView.backgroundColor = Color_White;
  85. }
  86. #pragma mark - 设置导航栏
  87. - (void)_setupNavigationItem{
  88. }
  89. #pragma mark - 设置子控件
  90. - (void)_setupSubViews{
  91. }
  92. #pragma mark - 布局子控件
  93. - (void)_makeSubViewsConstraints{
  94. }
  95. #pragma mark - Setter & Getter
  96. @end