123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- //
- // UITableView+MJRefreshAutoManager.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/23.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "UITableView+MJRefreshAutoManager.h"
- #define NO_MORE_DATA_TEXT @"无更多数据了"
- @implementation UITableView (MJRefreshAutoManager)
- static char stateKey;
- - (void)setFootRefreshState:(MJTableFooterRefreshState)footRefreshState {
-
-
- UIWindow *window = [UIApplication sharedApplication].keyWindow;
-
- [RACObserve(self.mj_footer, frame)subscribeNext:^(id x) { //这里的意思是监视mj_footer的frame变化,可以使用kvo代替RACObserve
- CGPoint point = [self convertPoint:self.mj_footer.frame.origin toView:window];
- if (point.y < window.frame.size.height) {
- [(MJRefreshAutoNormalFooter *)self.mj_footer setTitle:@"" forState:MJRefreshStateIdle];
- }else {
- [(MJRefreshAutoNormalFooter *)self.mj_footer setTitle:@"点击或上拉加载更多" forState:MJRefreshStateIdle];
- [(MJRefreshAutoNormalFooter *)self.mj_footer resetNoMoreData];
- }
- }];
-
- [self handleFooterRefresh:footRefreshState];
- NSString *value = [NSString stringWithFormat:@"%ld", (long)footRefreshState];
- objc_setAssociatedObject(self, &stateKey, value, OBJC_ASSOCIATION_COPY_NONATOMIC);
-
-
- }
- - (MJTableFooterRefreshState)footRefreshState {
-
- NSString *refreshState = objc_getAssociatedObject(self, &stateKey);
- if ([refreshState isEqualToString:@"MJTableFooterRefreshStateLoadMore"]) {
- return MJTableFooterRefreshStateNoMore;
- }
- else {
- return MJTableFooterRefreshStateLoadMore;
- }
-
- }
- - (void)handleFooterRefresh: (MJTableFooterRefreshState)footRefreshState {
-
- MJRefreshAutoNormalFooter *footer = (MJRefreshAutoNormalFooter*)self.mj_footer;
- switch (footRefreshState) {
- case MJTableFooterRefreshStateNormal:
- {
- [footer setTitle:@"" forState:MJRefreshStateIdle];
- break;
- }
-
- case MJTableFooterRefreshStateLoadMore:
- {
- [self.mj_footer endRefreshing];
- break;
- }
-
- case MJTableFooterRefreshStateNoMore:
- {
- [footer setTitle:NO_MORE_DATA_TEXT forState:MJRefreshStateNoMoreData];
- [self.mj_footer endRefreshingWithNoMoreData];
- // [(MJRefreshAutoNormalFooter *)self.mj_footer setTitle:@"到底了" forState:MJRefreshStateIdle];
- // [self.mj_footer endRefreshing];
- break;
-
- }
- default:
-
- break;
-
- }
-
- }
- @end
|