Created
April 26, 2010 19:52
-
-
Save lukeredpath/379795 to your computer and use it in GitHub Desktop.
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 UIViewController (NibCells) | |
- (UITableViewCell *)loadTableViewCellFromNibNamed:(NSString *)nibName; | |
- (UITableViewCell *)loadReusableTableViewCellFromNibNamed:(NSString *)nibName; | |
@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 UIViewController (NibCells) | |
- (UITableViewCell *)loadTableViewCellFromNibNamed:(NSString *)nibName; | |
{ | |
NSArray *bundleItems = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil]; | |
UITableViewCell *cell = nil; | |
for (id item in bundleItems) { | |
if ([item isKindOfClass:[UITableViewCell class]]) { | |
cell = item; | |
break; | |
} | |
} | |
NSAssert1(cell, @"Expected nib named %@ to contain a UITableViewCell", nibName); | |
return cell; | |
} | |
- (UITableViewCell *)loadReusableTableViewCellFromNibNamed:(NSString *)nibName; | |
{ | |
UITableViewCell *cell = [self loadTableViewCellFromNibNamed:nibName]; | |
NSAssert1(cell.reuseIdentifier, @"Cell in nib named %@ does not have a reuse identifier set", nibName); | |
NSAssert2([cell.reuseIdentifier isEqualToString:nibName], @"Expected cell to have a reuse identifier of %@, but it was %@", nibName, cell.reuseIdentifier); | |
return cell; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment