/
TableContainerView.m
165 lines (135 loc) · 4.83 KB
/
TableContainerView.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
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
//
// TableContainerView.m
// TVGuideDemo
//
// Created by pavan on 1/23/14.
// Copyright (c) 2014 pavan_saberjack. All rights reserved.
//
#import "TableContainerView.h"
#import "ShowCell.h"
static NSString *cellIdentifier = @"CellIdentifier";
@interface TableContainerView() <UITableViewDelegate, UITableViewDataSource, ShowCellDelegate>
@property (nonatomic, weak) UITableView *tableShows;
@end
@implementation TableContainerView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self addTableShows];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
#pragma mark UICreation Methods
- (void)addTableShows
{
[self addSubview:({
UITableView *tableShows = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStyleGrouped];
[tableShows setDelegate:self];
[tableShows setDataSource:self];
self.tableShows = tableShows;
[tableShows registerNib:[UINib nibWithNibName:@"ShowCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
tableShows;
})];
}
#pragma mark UITableViewDelegate methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80.0f;
}
#pragma mark UITableViewDataSource methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ShowCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
[cell setDelegate:self];
if (!cell)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellIdentifier owner:self options:nil];
cell = (ShowCell *)[nib objectAtIndex:0];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
return cell;
}
#pragma mark - ShowCellDelegate methods
- (void)showCell:(ShowCell *)cell collectionViewDidScroll:(UIScrollView *)scrollView
{
NSUInteger index = 0;
NSUInteger count = [self.tableShows.visibleCells count];
NSArray *visibleCells = self.tableShows.visibleCells;
NSIndexPath *path = [self.tableShows indexPathForCell:cell];
for(index = 0; index <count; index++)
{
ShowCell *subCell = visibleCells[index];
NSIndexPath *newPath = [self.tableShows indexPathForCell:subCell];
if ([newPath row] != [path row])
{
[subCell removeScrollingDelegates]; // remove the scroll Delegate
UICollectionView *collectionView = subCell.collectionView;
[collectionView setContentOffset:scrollView.contentOffset animated:NO];
}
}
}
- (void)showCell:(ShowCell *)cell collectionViewDidEndScroll:(UIScrollView *)scrollView
{
NSUInteger index = 0;
NSUInteger count = [self.tableShows.visibleCells count];
NSArray *visibleCells = self.tableShows.visibleCells;
NSIndexPath *path = [self.tableShows indexPathForCell:cell];
for(index = 0; index <count; index++)
{
ShowCell *subCell = visibleCells[index];
NSIndexPath *newPath = [self.tableShows indexPathForCell:subCell];
if ([newPath row] != [path row])
{
[subCell addScrollingDelegates];
}
}
}
- (void)showCell:(ShowCell *)cell collectionViewDidEndScrollAnimation:(UIScrollView *)scrollView
{
NSUInteger index = 0;
NSUInteger count = [self.tableShows.visibleCells count];
NSArray *visibleCells = self.tableShows.visibleCells;
NSIndexPath *path = [self.tableShows indexPathForCell:cell];
for(index = 0; index <count; index++)
{
ShowCell *subCell = visibleCells[index];
NSIndexPath *newPath = [self.tableShows indexPathForCell:subCell];
if ([newPath row] != [path row])
{
[subCell addScrollingDelegates];
}
}
}
- (void)showCell:(ShowCell *)cell collectionViewDidScrollDeaccelerate:(UIScrollView *)scrollView
{
NSUInteger index = 0;
NSUInteger count = [self.tableShows.visibleCells count];
NSArray *visibleCells = self.tableShows.visibleCells;
NSIndexPath *path = [self.tableShows indexPathForCell:cell];
for(index = 0; index <count; index++)
{
ShowCell *subCell = visibleCells[index];
NSIndexPath *newPath = [self.tableShows indexPathForCell:subCell];
if ([newPath row] != [path row])
{
[subCell removeScrollingDelegates]; // remove the scroll Delegate
UICollectionView *collectionView = subCell.collectionView;
[collectionView setContentOffset:scrollView.contentOffset animated:YES];
}
}
}
@end