Created
December 8, 2012 20:48
-
-
Save kulte/4241857 to your computer and use it in GitHub Desktop.
Smart UITableViewCell subclass to abstract away scattered cell boilerplate.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface KTEManagedTableViewCell : UITableViewCell { } | |
+ (id)cellForTableView:(UITableView *)tableView; | |
+ (id)cellForTableView:(UITableView *)tableView fromNib:(UINib *)nib; | |
+ (NSString *)cellIdentifier; | |
- (id)initWithCellIdentifer:(NSString *)cellID; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation KTEManagedTableViewCell | |
+ (id)cellForTableView:(UITableView *)tableView { | |
NSString *cellID = [self cellIdentifer]; | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; | |
if (cell == nil) { | |
cell = [[self alloc] initWithCellIdentifier:cellID]; | |
} | |
return cell; | |
} | |
+ (id)cellForTableView:(UITableView *)tableView fromNib:(UINib *)nib { | |
NSString *cellID = [self cellIdentifier]; | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; | |
if (cell == nil) { | |
NSArray *nibObjects = [nib instantiateWithOwner:nil options:nil]; | |
NSAssert2([...]); | |
cell = [nibObjects objectAtIndex:0]; | |
} | |
return cell; | |
} | |
+ (NSString *)cellIdentifier { | |
return NSStringFromClass([self class]); | |
} | |
- (id)initWithCellIdentifier:(NSString *)cellID { | |
return [self initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment