forked from danielctull/DTGridView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DTGridViewCell.m
97 lines (71 loc) · 1.94 KB
/
DTGridViewCell.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
//
// DTGridViewCell.m
// GridViewTester
//
// Created by Daniel Tull on 06.04.2009.
// Copyright 2009 Daniel Tull. All rights reserved.
//
#import "DTGridViewCell.h"
#import "DTGridView.h"
#pragma mark Private Methods
@interface DTGridViewCell ()
@property (nonatomic, copy) NSArray *codedSubviews;
- (DTGridView *)gridView;
@end
@implementation DTGridViewCell
@synthesize xPosition, yPosition, identifier, delegate, selected;
@synthesize highlighted;
@synthesize codedSubviews = _codedSubviews;
@dynamic frame;
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
self.codedSubviews = self.subviews;
}
return self;
}
- (id)initWithReuseIdentifier:(NSString *)anIdentifier {
self = [super initWithFrame:self.frame];
if (self) {
identifier = [anIdentifier copy];
for (UIView *codedSubview in self.codedSubviews) {
[self addSubview:codedSubview];
}
}
return self;
}
- (void)dealloc {
[identifier release];
[_codedSubviews release];
[super dealloc];
}
- (void)awakeFromNib {
[super awakeFromNib];
identifier = nil;
}
- (void)prepareForReuse {
self.selected = NO;
self.highlighted = NO;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.highlighted = YES;
[super touchesEnded:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
self.highlighted = NO;
[super touchesCancelled:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
self.highlighted = NO;
[[self gridView] selectRow:self.yPosition column:self.xPosition scrollPosition:DTGridViewScrollPositionNone animated:YES];
[self.delegate gridViewCellWasTouched:self];
[super touchesEnded:touches withEvent:event];
}
#pragma mark -
#pragma mark Private Methods
- (DTGridView *)gridView {
UIResponder *r = [self nextResponder];
if (![r isKindOfClass:[DTGridView class]]) return nil;
return (DTGridView *)r;
}
@end