MJRefreshFooter.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. @interface MJRefreshFooter()
  11. @end
  12. @implementation MJRefreshFooter
  13. #pragma mark - 构造方法
  14. + (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock
  15. {
  16. MJRefreshFooter *cmp = [[self alloc] init];
  17. cmp.refreshingBlock = refreshingBlock;
  18. return cmp;
  19. }
  20. + (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action
  21. {
  22. MJRefreshFooter *cmp = [[self alloc] init];
  23. [cmp setRefreshingTarget:target refreshingAction:action];
  24. return cmp;
  25. }
  26. #pragma mark - 重写父类的方法
  27. - (void)prepare
  28. {
  29. [super prepare];
  30. // 设置自己的高度
  31. self.mj_h = MJRefreshFooterHeight;
  32. // 默认是自动隐藏
  33. self.automaticallyHidden = YES;
  34. }
  35. - (void)willMoveToSuperview:(UIView *)newSuperview
  36. {
  37. [super willMoveToSuperview:newSuperview];
  38. if (newSuperview) {
  39. // 监听scrollView数据的变化
  40. if ([self.scrollView isKindOfClass:[UITableView class]] || [self.scrollView isKindOfClass:[UICollectionView class]]) {
  41. [self.scrollView setMj_reloadDataBlock:^(NSInteger totalDataCount) {
  42. if (self.isAutomaticallyHidden) {
  43. self.hidden = (totalDataCount == 0);
  44. }
  45. }];
  46. }
  47. }
  48. }
  49. #pragma mark - 公共方法
  50. - (void)endRefreshingWithNoMoreData
  51. {
  52. self.state = MJRefreshStateNoMoreData;
  53. }
  54. - (void)noticeNoMoreData
  55. {
  56. [self endRefreshingWithNoMoreData];
  57. }
  58. - (void)resetNoMoreData
  59. {
  60. self.state = MJRefreshStateIdle;
  61. }
  62. @end