Repository navigation
Expand file tree
/
Copy pathBASeparatedTableProvider.m
More file actions
192 lines (150 loc) · 9.04 KB
/
Copy pathBASeparatedTableProvider.m
File metadata and controls
192 lines (150 loc) · 9.04 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
Copyright 2011 Dmitry Stadnik. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of Dmitry Stadnik.
*/
#import "BASeparatedTableProvider.h"
@implementation BASeparatedTableProvider
- (id<BASeparatedTableProviderDelegate>)delegate {
return (id<BASeparatedTableProviderDelegate>)[super delegate];
}
- (void)setDelegate:(id<BASeparatedTableProviderDelegate>)delegate {
[super setDelegate:delegate];
}
- (NSIndexPath *)separatedIndexPathForIndexPath:(NSIndexPath *)indexPath {
return [NSIndexPath indexPathForRow:((indexPath.row * 3) + 1) inSection:indexPath.section];
}
- (NSArray *)separatedIndexPathsForIndexPaths:(NSArray *)indexPaths {
if (!indexPaths) {
return nil;
}
NSMutableArray *separatedIndexPaths = [NSMutableArray arrayWithCapacity:([indexPaths count] * 3)];
for (NSIndexPath *indexPath in indexPaths) {
[separatedIndexPaths addObject:[NSIndexPath indexPathForRow:((indexPath.row * 3) + 0) inSection:indexPath.section]];
[separatedIndexPaths addObject:[NSIndexPath indexPathForRow:((indexPath.row * 3) + 1) inSection:indexPath.section]];
[separatedIndexPaths addObject:[NSIndexPath indexPathForRow:((indexPath.row * 3) + 2) inSection:indexPath.section]];
}
return separatedIndexPaths;
}
// Table Data Source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger rowsCount = [self.delegate tableView:tableView numberOfRowsInSection:section];
return rowsCount * 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *sourceIndexPath = [NSIndexPath indexPathForRow:(indexPath.row / 3) inSection:indexPath.section];
switch (indexPath.row % 3) {
case 0: return [self.delegate tableView:tableView topSeparatorCellForRowAtIndexPath:sourceIndexPath];
case 1: return [self.delegate tableView:tableView cellForRowAtIndexPath:sourceIndexPath];
case 2: return [self.delegate tableView:tableView bottomSeparatorCellForRowAtIndexPath:sourceIndexPath];
}
return nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if ([self.delegate respondsToSelector:@selector(numberOfSectionsInTableView:)]) {
return [self.delegate numberOfSectionsInTableView:tableView];
}
return 1;
}
//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
// if ([self.delegate respondsToSelector:@selector(tableView:titleForHeaderInSection:)]) {
// return [self.delegate tableView:tableView titleForHeaderInSection:section];
// }
// return nil;
//}
//
//- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
// if ([self.delegate respondsToSelector:@selector(tableView:titleForFooterInSection:)]) {
// return [self.delegate tableView:tableView titleForFooterInSection:section];
// }
// return nil;
//}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
if ((indexPath.row % 3 == 1) && [self.delegate respondsToSelector:@selector(tableView:canEditRowAtIndexPath:)]) {
NSIndexPath *sourceIndexPath = [NSIndexPath indexPathForRow:(indexPath.row / 3) inSection:indexPath.section];
return [self.delegate tableView:tableView canEditRowAtIndexPath:sourceIndexPath];
}
return NO;
}
//- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
//- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;
//- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ((indexPath.row % 3 == 1) && [self.delegate respondsToSelector:@selector(tableView:commitEditingStyle:forRowAtIndexPath:)]) {
NSIndexPath *sourceIndexPath = [NSIndexPath indexPathForRow:(indexPath.row / 3) inSection:indexPath.section];
[self.delegate tableView:tableView commitEditingStyle:editingStyle forRowAtIndexPath:sourceIndexPath];
}
}
//- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;
// Table Delegate
//- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *sourceIndexPath = [NSIndexPath indexPathForRow:(indexPath.row / 3) inSection:indexPath.section];
switch (indexPath.row % 3) {
case 0: {
const BACellSeparatorPositions positions = [self.delegate tableView:tableView separatorPositionsForRow:sourceIndexPath];
if (positions & BACellSeparatorPositionTop) {
return [self.delegate tableView:tableView heightForTopSeparatorRowAtIndexPath:sourceIndexPath];
}
return 0;
}
case 1:
if ([self.delegate respondsToSelector:@selector(tableView:heightForRowAtIndexPath:)]) {
return [self.delegate tableView:tableView heightForRowAtIndexPath:sourceIndexPath];
}
return 0;
case 2: {
const BACellSeparatorPositions positions = [self.delegate tableView:tableView separatorPositionsForRow:sourceIndexPath];
if (positions & BACellSeparatorPositionBottom) {
return [self.delegate tableView:tableView heightForBottomSeparatorRowAtIndexPath:sourceIndexPath];
}
return 0;
}
}
return 0;
}
//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
//- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
//- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
//- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ((indexPath.row % 3 == 1) && [self.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
[self.delegate tableView:tableView
didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:(indexPath.row / 3) inSection:indexPath.section]];
}
}
//- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath;
//- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
//- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath;
//- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath;
//- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;
//- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath;
//- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath;
//- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath;
//- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath;
//- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender;
//- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender;
@end