-
Notifications
You must be signed in to change notification settings - Fork 73
/
ALValueCell.m
87 lines (66 loc) · 1.88 KB
/
ALValueCell.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
#import "ALValueCell.h"
@implementation ALValueCell
@synthesize delegate;
- (void)loadValue:(id)value
{
}
- (void)loadValue:(id)value withTitle:(NSString *)title
{
[self loadValue:value];
}
- (void)didSelect
{
}
@end
@implementation ALSwitchCell
@synthesize switchView;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
[switchView addTarget:self action:@selector(valueChanged) forControlEvents:UIControlEventValueChanged];
[self setAccessoryView:switchView];
}
return self;
}
- (void)dealloc
{
[switchView release];
[super dealloc];
}
- (void)loadValue:(id)value
{
switchView.on = [value boolValue];
}
- (void)valueChanged
{
id value = [NSNumber numberWithBool:switchView.on];
[[self delegate] valueCell:self didChangeToValue:value];
}
@end
@implementation ALCheckCell
- (void)loadValue:(id)value
{
[self setAccessoryType:[value boolValue] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone];
}
- (void)didSelect
{
UITableViewCellAccessoryType type = [self accessoryType];
[self setAccessoryType:(type == UITableViewCellAccessoryNone) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone];
id value = [NSNumber numberWithBool:type == UITableViewCellAccessoryNone];
[[self delegate] valueCell:self didChangeToValue:value];
}
@end
@implementation ALDisclosureIndicatedCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if ((self = [super initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier])) {
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return self;
}
- (void)loadValue:(id)value withTitle:(NSString *)title
{
self.detailTextLabel.text = title ?: [value description];
}
@end