-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpSideDownTableView.m
More file actions
165 lines (107 loc) · 3.81 KB
/
UpSideDownTableView.m
File metadata and controls
165 lines (107 loc) · 3.81 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
154
155
156
157
158
159
160
161
162
163
164
165
//
// UpSideDownTableView.m
// Dealabs
//
// Created by Raphaël Pinto on 10/06/2015.
// Copyright (c) 2015 HUME Network. All rights reserved.
//
#import "UpSideDownTableView.h"
#import "MagicPullToRefreshView.h"
#import "MagicModel.h"
@implementation UpSideDownTableView
#pragma mark -
#pragma mark UI Table View Delegate Methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// Keep this empty to prevent magic table view paging
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if (!self.mPagingDisabled)
{
if (self.contentOffset.y < 50)
{
if ([self.mMagicTableViewDataSource respondsToSelector:@selector(isLoadingMagicTableView:)] && ![self.mMagicTableViewDataSource isLoadingMagicTableView:self])
{
[self.mMagicTableViewDataSource magicTableViewDidTriggerPaging:self];
[self startLoadingTableViewPagingFooter];
return;
}
}
}
}
/*
#pragma mark -
#pragma mark Data Management Methods
- (float)totalCellsHeight
{
NSInteger lNumberOfSection = 0;
if ([self.dataSource respondsToSelector:@selector(numberOfSectionsInTableView:)])
{
lNumberOfSection = [self.dataSource numberOfSectionsInTableView:self];
}
float lTotal = 0.0f;
for (int i = 0; i < lNumberOfSection; i++)
{
NSInteger lNumberOfCells = 0;
if ([self.dataSource respondsToSelector:@selector(tableView:numberOfRowsInSection:)])
{
lNumberOfCells = [self.dataSource tableView:self numberOfRowsInSection:i];
}
for (int y = 0; y < lNumberOfCells; y++)
{
UITableViewCell* lCell = [self.dataSource tableView:self cellForRowAtIndexPath:[NSIndexPath indexPathForItem:y inSection:i]];
lTotal += lCell.frame.size.height;
}
}
return lTotal;
}*/
#pragma mark -
#pragma mark Magic Model Delgate Methods
- (void)magicModelDisablePaging:(MagicModel*)_MagicModel
{
self.mPagingDisabled = YES;
if (self.mPagingFooterView)
{
[self.mPagingFooterView stopLoadingForMagicTableView:self];
}
if (self.mDefaultFooterView)
{
self.tableHeaderView = self.mDefaultFooterView;
}
}
- (void)magicModelEnablePaging:(MagicModel*)_MagicModel
{
self.mPagingDisabled = NO;
self.mPagingFooterView = [self.mMagicTableViewDelegate MagicTableViewPagingFooter:self];
[self.mPagingFooterView startLoadingForMagicTableView:self];
self.tableHeaderView = self.mPagingFooterView;
float lOffsetY = MAX(self.contentSize.height - self.frame.size.height + 40, 0);
[self setContentOffset:CGPointMake(0, lOffsetY) animated:NO];
}
- (void)addEmptyFooterView
{
self.tableFooterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.tableHeaderView.frame.size.height)] autorelease];
}
- (void)magicModelResultsReceived:(MagicModel*)_MagicModel forPage:(NSNumber*)_Page
{
self.alwaysBounceVertical = NO;
[self stopLoadingTableVIewPagingFooter];
[self.mLoadingView removeFromSuperview];
[self.mEmptyStateView removeFromSuperview];
self.mEmptyStateView = nil;
[self.mPullToRefreshView magicModelResultsReceived:_MagicModel forScrollView:self];
[self updateEmptyStateView];
float lCurrentContentHeight = self.contentSize.height;
[self reloadData];
if ([_Page intValue] == 1)
{
float lOffsetY = MAX(self.contentSize.height - self.frame.size.height, 0);
[self setContentOffset:CGPointMake(0, lOffsetY) animated:NO];
}
else
{
[self setContentOffset:CGPointMake(0, self.contentSize.height - lCurrentContentHeight ) animated:NO];
}
}
@end