Repository navigation
Expand file tree
/
Copy pathCNTableViewController.m
More file actions
executable file
·154 lines (102 loc) · 4.18 KB
/
Copy pathCNTableViewController.m
File metadata and controls
executable file
·154 lines (102 loc) · 4.18 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// Created by Ravel Antunes on 10/31/12.
// Copyright (c) 2012 Riptide Software. All rights reserved.
//
#import "CNTableViewController.h"
#import "CNTableHeader.h"
@implementation CNTableViewController
@synthesize reloading=_reloading;
@synthesize refreshHeaderView;
#pragma mark -
#pragma mark View lifecycle
#define SENSIBILITY 50.0f
- (void)viewDidLoad {
[super viewDidLoad];
if (refreshHeaderView == nil) {
refreshHeaderView = [[CNTableHeader alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, 320.0f, self.tableView.bounds.size.height)];
refreshHeaderView.backgroundColor = [UIColor blackColor];
refreshHeaderView.bottomBorderThickness = 1.0;
[self.tableView addSubview:refreshHeaderView];
self.tableView.showsVerticalScrollIndicator = YES;
[self setupTableViewFooter];
}
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
return cell;
}
#pragma mark -
#pragma mark ScrollView Callbacks
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.isDragging) {
if (refreshHeaderView.state == EGOOPullRefreshPulling && scrollView.contentOffset.y > -SENSIBILITY && scrollView.contentOffset.y < 0.0f && !_reloading) {
[refreshHeaderView setState:EGOOPullRefreshNormal];
} else if (refreshHeaderView.state == EGOOPullRefreshNormal && scrollView.contentOffset.y < -SENSIBILITY && !_reloading) {
[refreshHeaderView setState:EGOOPullRefreshPulling];
}
}
if (scrollView.contentOffset.y == scrollView.contentSize.height - scrollView.bounds.size.height)
{
[self loadMore];
}
}
#pragma mark Load More Call Back
- (void)loadMore{
NSLog(@"Please override loadMore.");
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if (scrollView.contentOffset.y <= - SENSIBILITY && !_reloading) {
_reloading = YES;
[self reloadTableViewDataSource];
[refreshHeaderView setState:EGOOPullRefreshLoading];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
self.tableView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);
[UIView commitAnimations];
}
}
#pragma mark -
#pragma mark refreshHeaderView Methods
- (void)dataSourceDidFinishLoadingNewData{
[refreshHeaderView setCurrentDate];
_reloading = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
[self.tableView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)];
[UIView commitAnimations];
[refreshHeaderView setState:EGOOPullRefreshNormal];
}
- (void) reloadTableViewDataSource
{
NSLog(@"Please override reloadTableViewDataSource");
}
#pragma mark Footer
- (void)setupTableViewFooter
{
// set up label
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
footerView.backgroundColor = [UIColor clearColor];
footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
footerLabel.font = [UIFont boldSystemFontOfSize:16];
footerLabel.textColor = [UIColor whiteColor];
[footerLabel setBackgroundColor:[UIColor clearColor]];
footerLabel.textAlignment = UITextAlignmentCenter;
footerActivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
footerActivityIndicator.center = CGPointMake(40, 22);
footerActivityIndicator.hidesWhenStopped = YES;
[footerActivityIndicator setColor:[UIColor whiteColor]];
[footerView addSubview:footerLabel];
[footerView addSubview:footerActivityIndicator];
self.tableView.tableFooterView = footerView;
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
refreshHeaderView=nil;
}
@end