MJRefreshFooter.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // 代码地址: https://github.com/CoderMJLee/MJRefresh
  2. // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
  3. // MJRefreshFooter.m
  4. // MJRefreshExample
  5. //
  6. // Created by MJ Lee on 15/3/5.
  7. // Copyright (c) 2015年 小码哥. All rights reserved.
  8. //
  9. #import "MJRefreshFooter.h"
  10. #include "UIScrollView+MJRefresh.h"
  11. @interface MJRefreshFooter()
  12. @end
  13. @implementation MJRefreshFooter
  14. #pragma mark - 构造方法
  15. + (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock
  16. {
  17. MJRefreshFooter *cmp = [[self alloc] init];
  18. cmp.refreshingBlock = refreshingBlock;
  19. return cmp;
  20. }
  21. + (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action
  22. {
  23. MJRefreshFooter *cmp = [[self alloc] init];
  24. [cmp setRefreshingTarget:target refreshingAction:action];
  25. return cmp;
  26. }
  27. #pragma mark - 重写父类的方法
  28. - (void)prepare
  29. {
  30. [super prepare];
  31. // 设置自己的高度
  32. self.mj_h = MJRefreshFooterHeight;
  33. // 默认不会自动隐藏
  34. self.automaticallyHidden = NO;
  35. }
  36. - (void)willMoveToSuperview:(UIView *)newSuperview
  37. {
  38. [super willMoveToSuperview:newSuperview];
  39. if (newSuperview) {
  40. // 监听scrollView数据的变化
  41. if ([self.scrollView isKindOfClass:[UITableView class]] || [self.scrollView isKindOfClass:[UICollectionView class]]) {
  42. [self.scrollView setMj_reloadDataBlock:^(NSInteger totalDataCount) {
  43. if (self.isAutomaticallyHidden) {
  44. self.hidden = (totalDataCount == 0);
  45. }
  46. }];
  47. }
  48. }
  49. }
  50. #pragma mark - 公共方法
  51. - (void)endRefreshingWithNoMoreData
  52. {
  53. MJRefreshDispatchAsyncOnMainQueue(self.state = MJRefreshStateNoMoreData;)
  54. }
  55. - (void)noticeNoMoreData
  56. {
  57. [self endRefreshingWithNoMoreData];
  58. }
  59. - (void)resetNoMoreData
  60. {
  61. MJRefreshDispatchAsyncOnMainQueue(self.state = MJRefreshStateIdle;)
  62. }
  63. - (void)setAutomaticallyHidden:(BOOL)automaticallyHidden
  64. {
  65. _automaticallyHidden = automaticallyHidden;
  66. }
  67. @end