-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomViewCell.m
101 lines (82 loc) · 2.96 KB
/
CustomViewCell.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
//
// CustomViewCell.m
// AvocadoTest1
//
// Created by Jake on 12-02-16.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "CustomViewCell.h"
#import "Utilities.h"
@implementation CustomViewCell
+(CustomViewCell *)customViewCellFromData:(id)data
{
for (Class eachSubclass in [CustomViewCell subclasses]) {
if ([eachSubclass canDisplayData:data]) {
CustomViewCell *returnCell = [[eachSubclass alloc] init];
[returnCell setData:data];
return returnCell;
}
}
CLLog(LOG_LEVEL_WARNING, @"An unknown data type was passed to customViewCellFromData.");
return nil;
}
+(NSString *)cellIdentifierForData:(id)data
{
for (Class eachSubclass in [CustomViewCell subclasses]) {
if ([eachSubclass canDisplayData:data]) {
return [eachSubclass cellIdentifier];
}
}
CLLog(LOG_LEVEL_WARNING, @"An unknown data type was passed to cellIdentifierForData.");
return nil;
}
+(CGFloat)cellHeightForData:(id)data
{
for (Class eachSubclass in [CustomViewCell subclasses]) {
if ([eachSubclass canDisplayData:data]) {
return [eachSubclass cellHeightForData:data];
}
}
CLLog(LOG_LEVEL_WARNING, @"An unknown data type was passed to cellHeightForData.");
return 0;
}
+(BOOL)canDisplayData:(id)data
{
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
userInfo:nil];
}
+(NSString*)cellIdentifier{
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
userInfo:nil];
}
- (id)init
{
self = [super initWithStyle:[[self class] cellStyle] reuseIdentifier:[[self class] cellIdentifier]];
if (self) {
[self setSelectionStyle:UITableViewCellSelectionStyleNone];
UIFont *titleFont = [UIFont fontWithName:@"HelveticaNeue-Medium" size:17];
UIFont *descFont = [UIFont fontWithName:@"HelveticaNeue" size:17];
[[self textLabel] setFont:titleFont];
[[self detailTextLabel] setFont:descFont];
[[self textLabel] setAdjustsFontSizeToFitWidth:YES];
[[self detailTextLabel] setAdjustsFontSizeToFitWidth:YES];
}
return self;
}
-(void) setData:(id) data
{
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
userInfo:nil];
}
+(UITableViewCellStyle)cellStyle
{
return UITableViewCellStyleValue1;
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end