EMRefreshTableViewController.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // XHRefreshTableViewController.m
  3. // DXStudio
  4. //
  5. // Created by XieYajie on 18/08/2017.
  6. // Copyright © 2017 dxstudio. All rights reserved.
  7. //
  8. #import "EMRefreshTableViewController.h"
  9. #import "MJRefresh.h"
  10. @interface EMRefreshTableViewController ()
  11. @end
  12. @implementation EMRefreshTableViewController
  13. @synthesize rightItems = _rightItems;
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. // Uncomment the following line to preserve selection between presentations.
  17. if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
  18. [self setEdgesForExtendedLayout:UIRectEdgeNone];
  19. }
  20. self.tableView.tableFooterView = self.defaultFooterView;
  21. _page = 0;
  22. _showRefreshHeader = NO;
  23. _showRefreshFooter = NO;
  24. }
  25. - (void)didReceiveMemoryWarning {
  26. [super didReceiveMemoryWarning];
  27. // Dispose of any resources that can be recreated.
  28. }
  29. #pragma mark - setter
  30. //- (void)setRefreshHeaderColor:(UIColor *)aColor
  31. //{
  32. // if (self.showRefreshHeader && self.tableView.mj_header) {
  33. // [(MJRefreshNormalHeader *)self.tableView.mj_header setRefreshHeaderColor:aColor];
  34. // }
  35. //}
  36. - (void)setShowRefreshHeader:(BOOL)showRefreshHeader
  37. {
  38. if (_showRefreshHeader != showRefreshHeader) {
  39. _showRefreshHeader = showRefreshHeader;
  40. if (_showRefreshHeader) {
  41. __weak typeof(self) weakSelf = self;
  42. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  43. [weakSelf tableViewDidTriggerHeaderRefresh];
  44. }];
  45. self.tableView.mj_header.accessibilityIdentifier = @"refresh_header";
  46. }
  47. else{
  48. [self.tableView setMj_header:nil];
  49. }
  50. }
  51. }
  52. - (void)setShowRefreshFooter:(BOOL)showRefreshFooter
  53. {
  54. if (_showRefreshFooter != showRefreshFooter) {
  55. _showRefreshFooter = showRefreshFooter;
  56. if (_showRefreshFooter) {
  57. __weak typeof(self) weakSelf = self;
  58. self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  59. [weakSelf tableViewDidTriggerFooterRefresh];
  60. }];
  61. self.tableView.mj_footer.accessibilityIdentifier = @"refresh_footer";
  62. }
  63. else{
  64. [self.tableView setMj_footer:nil];
  65. }
  66. }
  67. }
  68. #pragma mark - getter
  69. - (NSMutableArray *)dataArray
  70. {
  71. if (_dataArray == nil) {
  72. _dataArray = [NSMutableArray array];
  73. }
  74. return _dataArray;
  75. }
  76. - (NSMutableDictionary *)dataDictionary
  77. {
  78. if (_dataDictionary == nil) {
  79. _dataDictionary = [NSMutableDictionary dictionary];
  80. }
  81. return _dataDictionary;
  82. }
  83. - (UIView *)defaultFooterView
  84. {
  85. if (_defaultFooterView == nil) {
  86. _defaultFooterView = [[UIView alloc] init];
  87. }
  88. return _defaultFooterView;
  89. }
  90. #pragma mark - Table view data source
  91. //- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  92. //{
  93. // // Return the number of sections.
  94. // return 1;
  95. //}
  96. //
  97. //- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  98. //{
  99. // // Return the number of rows in the section.
  100. // return 0;
  101. //}
  102. //
  103. //- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  104. //{
  105. // static NSString *CellIdentifier = @"UITableViewCell";
  106. // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  107. //
  108. // // Configure the cell...
  109. //
  110. // return cell;
  111. //}
  112. #pragma mark - public refresh
  113. - (void)autoTriggerHeaderRefresh
  114. {
  115. if (self.showRefreshHeader) {
  116. [self tableViewDidTriggerHeaderRefresh];
  117. }
  118. }
  119. - (void)tableViewDidTriggerHeaderRefresh
  120. {
  121. }
  122. - (void)tableViewDidTriggerFooterRefresh
  123. {
  124. }
  125. - (void)tableViewDidFinishTriggerHeader:(BOOL)isHeader reload:(BOOL)reload
  126. {
  127. __weak typeof(self) weakSelf = self;
  128. dispatch_async(dispatch_get_main_queue(), ^{
  129. if (reload) {
  130. [weakSelf.tableView reloadData];
  131. }
  132. if (isHeader) {
  133. [weakSelf.tableView.mj_header endRefreshing];
  134. }
  135. else{
  136. [weakSelf.tableView.mj_footer endRefreshing];
  137. }
  138. });
  139. }
  140. @end