-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUITableViewCell+NIB-1.m
41 lines (28 loc) · 1.13 KB
/
UITableViewCell+NIB-1.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
#import "UITableViewCell+NIB.h"
@implementation UITableViewCell (NIB)
+ (id)loadCell {
return [self loadCellWithNibName:[self nibName]];
}
+ (id)loadCellWithNibName:(NSString*)nibName {
NSArray* objects = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil];
for (id object in objects) {
if ([object isKindOfClass:self]) {
UITableViewCell *cell = object;
[cell setValue:nibName forKey:@"_reuseIdentifier"];
return cell;
}
}
[NSException raise:@"WrongNibFormat" format:@"Nib for '%@' must contain one TableViewCell, and its class must be '%@'", nibName, [self class]];
return nil;
}
+ (NSString*)cellID { return [self description]; }
+ (NSString*)nibName { return [self description]; }
+ (id)dequeOrCreateInTable:(UITableView*)tableView {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:[self cellID]];
return cell ? cell : [self loadCell];
}
+ (id)dequeOrCreateInTable:(UITableView*)tableView withNibname:(NSString*)nibName{
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:nibName];
return cell ? cell : [self loadCellWithNibName:nibName];
}
@end