-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUITableView+CellCreation.m
52 lines (42 loc) · 1.65 KB
/
UITableView+CellCreation.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
//
// UITableView+CellCreation.m
// WorldlifeNMP
//
// Created by Evgeniy Kirpichenko on 7/5/12.
// Copyright (c) 2012 MLS. All rights reserved.
//
#import "UITableView+CellCreation.h"
@implementation UITableView (CellCreation)
- (id) cellForClass:(Class) CellClass {
if (![CellClass isSubclassOfClass:[UITableViewCell class]]) {
NSString *className = NSStringFromClass(CellClass);
[NSException raise:@"Wrong class"
format:@"%@ is not subclass of UITableViewCell",className];
}
NSString* cellIdentifier = NSStringFromClass(CellClass);
UITableViewCell* cell = [self dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:cellIdentifier
owner:nil
options:nil];
for(id currentObject in topLevelObjects) {
if([currentObject isKindOfClass:CellClass]) {
return currentObject;
}
}
}
return cell;
}
- (UITableViewCell *) baseCellWithStyle:(UITableViewCellStyle) style
identifier:(NSString *) identifier
{
UITableViewCell* cell = [self dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:style reuseIdentifier:identifier];
}
return cell;
}
- (UITableViewCell *) baseCellWithIdentifier:(NSString *) identifier {
return [self baseCellWithStyle:UITableViewCellStyleDefault identifier:identifier];
}
@end