-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewController.m
88 lines (74 loc) · 2.54 KB
/
ViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// ViewController.m
// EZRefreshTabelHeaderView
//
// Created by ye on 15/12/15.
// Copyright © 2015年 4GInter. All rights reserved.
//
#import "ViewController.h"
#import "EZRefreshTableHeaderFooter.h"
@interface ViewController () <UITableViewDataSource, UITableViewDelegate, EZRefreshTableHeaderViewDelegate>
@property (nonatomic, strong) NSMutableArray *array;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_array = [[NSMutableArray alloc] initWithCapacity:20];
_refreshHeader = [[EZRefreshTableHeaderFooter alloc] initWithTableView:_tableView direction:EZRefreshTableHeaderPullDirectionUp|EZRefreshTableHeaderPullDirectionDown];
_refreshHeader.delegate = self;
[self initData];
}
- (void)initData
{
[_array removeAllObjects];
for (NSInteger i = 0; i < 5; i++) {
[_array addObject:@(i)];
}
[_tableView reloadData];
[_refreshHeader didFinishRefresh];
}
- (void)getMoreData
{
NSInteger count = _array.count;
for (NSInteger i = count; i < count + 3; i++) {
[_array addObject:@(i)];
}
[_tableView reloadData];
[_refreshHeader didFinishRefresh];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _array.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 44;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSNumber *num = _array[indexPath.row];
cell.textLabel.text = num.stringValue;
return cell;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
[_refreshHeader tableViewDidEndDragging];
}
- (BOOL)refreshHeaderSholdStartRefresh:(EZRefreshTableHeaderFooter *)headerFooter forDirection:(EZRefreshTableHeaderPullDirection)direction
{
return YES;
}
- (void)refreshHeaderDidStartRefresh:(EZRefreshTableHeaderFooter *)headerFooter forDirection:(EZRefreshTableHeaderPullDirection)direction
{
if (direction == EZRefreshTableHeaderPullDirectionUp) {
[self performSelector:@selector(getMoreData) withObject:nil afterDelay:2];
} else if (direction == EZRefreshTableHeaderPullDirectionDown) {
[self performSelector:@selector(initData) withObject:nil afterDelay:2];
}
}
@end