forked from soffes/sstoolkit
-
Notifications
You must be signed in to change notification settings - Fork 100
/
SSCollectionViewItemTableViewCell.m
96 lines (68 loc) · 2.13 KB
/
SSCollectionViewItemTableViewCell.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
//
// SSCollectionViewItemTableViewCell.m
// SSToolkit
//
// Created by Sam Soffes on 3/10/11.
// Copyright 2011 Sam Soffes. All rights reserved.
//
#import "SSCollectionViewItemTableViewCell.h"
#import "SSCollectionViewItem.h"
#import "SSCollectionView.h"
#import "SSCollectionViewInternal.h"
@implementation SSCollectionViewItemTableViewCell
#pragma mark - Accessors
@synthesize itemSize = _itemSize;
@synthesize itemSpacing = _itemSpacing;
@synthesize items = _items;
- (void)setItems:(NSArray *)someItems {
[_items makeObjectsPerformSelector:@selector(removeFromSuperview)];
_items = someItems;
if (_items == nil) {
return;
}
[_items enumerateObjectsUsingBlock:^(id object, NSUInteger index, BOOL *stop) {
[self addSubview:(UIView *)object];
}];
[self setNeedsLayout];
}
@synthesize collectionView = _collectionView;
#pragma mark - NSObject
- (void)dealloc {
self.collectionView = nil;
self.items = nil;
}
#pragma mark - UIView
- (void)layoutSubviews {
__block CGFloat x = _itemSpacing;
[_items enumerateObjectsUsingBlock:^(id object, NSUInteger index, BOOL *stop) {
SSCollectionViewItem *item = (SSCollectionViewItem *)object;
item.frame = CGRectMake(x, 0.0f, _itemSize.width, _itemSize.height);
x += _itemSize.width + _itemSpacing;
}];
}
#pragma mark - UITableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier])) {
self.backgroundView.hidden = YES;
self.selectedBackgroundView.hidden = YES;
self.contentView.hidden = YES;
self.textLabel.hidden = YES;
self.detailTextLabel.hidden = YES;
self.imageView.hidden = YES;
self.selectionStyle = UITableViewCellSelectionStyleNone;
_itemSize = CGSizeZero;
_itemSpacing = 0.0f;
}
return self;
}
- (void)prepareForReuse {
[super prepareForReuse];
[self.collectionView _reuseItems:_items];
self.items = nil;
}
#pragma mark - Initializer
- (id)initWithReuseIdentifier:(NSString *)aReuseIdentifier {
self = [self initWithStyle:UITableViewCellStyleDefault reuseIdentifier:aReuseIdentifier];
return self;
}
@end