Skip to content

Commit

Permalink
delay swizzle code of reloadData
Browse files Browse the repository at this point in the history
建议大家不要去使用mj_footer.automaticallyHidden = YES;
由开发者自己去控制footer的显示和隐藏是最灵活的
  • Loading branch information
520dev committed Nov 21, 2017
1 parent 459415d commit 65ce2ea
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 15 deletions.
6 changes: 3 additions & 3 deletions MJRefresh.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = 'MJRefresh'
s.version = '3.1.15'
s.version = '3.1.15.1'
s.summary = 'An easy way to use pull-to-refresh'
s.homepage = 'https://github.com/CoderMJLee/MJRefresh'
s.license = 'MIT'
s.authors = {'MJ Lee' => '199109106@qq.com'}
s.authors = {'MJ Lee' => 'richermj123go@vip.qq.com'}
s.platform = :ios, '6.0'
s.source = {:git => 'https://github.com/CoderMJLee/MJRefresh.git', :tag => s.version}
s.source_files = 'MJRefresh/**/*.{h,m}'
s.source_files = 'MJRefresh/*.{h,m}'
s.resource = 'MJRefresh/MJRefresh.bundle'
s.requires_arc = true
end
17 changes: 17 additions & 0 deletions MJRefresh/Base/MJRefreshFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//

#import "MJRefreshFooter.h"
#include "UIScrollView+MJRefresh.h"

@interface MJRefreshFooter()

Expand Down Expand Up @@ -75,4 +76,20 @@ - (void)resetNoMoreData
self.state = MJRefreshStateIdle;
});
}

- (void)setAutomaticallyHidden:(BOOL)automaticallyHidden
{
_automaticallyHidden = automaticallyHidden;

if (automaticallyHidden) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[UITableView exchangeInstanceMethod1:@selector(reloadData) method2:@selector(mj_reloadData)];
[UICollectionView exchangeInstanceMethod1:@selector(reloadData) method2:@selector(mj_reloadData)];
});
#pragma clang diagnostic pop
}
}
@end
2 changes: 1 addition & 1 deletion MJRefresh/Base/MJRefreshHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change

// 在刷新的refreshing状态
if (self.state == MJRefreshStateRefreshing) {
if (self.window == nil) return;
// if (self.window == nil) return;

// sectionheader停留解决
CGFloat insetT = - self.scrollView.mj_offsetY > _scrollViewOriginalInset.top ? - self.scrollView.mj_offsetY : _scrollViewOriginalInset.top;
Expand Down
5 changes: 5 additions & 0 deletions MJRefresh/UIScrollView+MJRefresh.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

@class MJRefreshHeader, MJRefreshFooter;

@interface NSObject (MJRefresh)
+ (void)exchangeInstanceMethod1:(SEL)method1 method2:(SEL)method2;
+ (void)exchangeClassMethod1:(SEL)method1 method2:(SEL)method2;
@end

@interface UIScrollView (MJRefresh)
/** 下拉刷新控件 */
@property (strong, nonatomic) MJRefreshHeader *mj_header;
Expand Down
10 changes: 0 additions & 10 deletions MJRefresh/UIScrollView+MJRefresh.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ - (void)executeReloadDataBlock

@implementation UITableView (MJRefresh)

+ (void)load
{
[self exchangeInstanceMethod1:@selector(reloadData) method2:@selector(mj_reloadData)];
}

- (void)mj_reloadData
{
[self mj_reloadData];
Expand All @@ -149,11 +144,6 @@ - (void)mj_reloadData

@implementation UICollectionView (MJRefresh)

+ (void)load
{
[self exchangeInstanceMethod1:@selector(reloadData) method2:@selector(mj_reloadData)];
}

- (void)mj_reloadData
{
[self mj_reloadData];
Expand Down
1 change: 0 additions & 1 deletion MJRefreshExample/Classes/Second/MJTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ - (void)example14
- (void)reset
{
[self.tableView.mj_footer setRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
// [self.tableView.mj_footer beginRefreshing];
[self.tableView.mj_footer resetNoMoreData];
}

Expand Down
25 changes: 25 additions & 0 deletions MJRefreshExample/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -31,6 +41,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down Expand Up @@ -65,6 +85,11 @@
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down

0 comments on commit 65ce2ea

Please sign in to comment.