Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created April 26, 2010 19:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeredpath/379795 to your computer and use it in GitHub Desktop.
Save lukeredpath/379795 to your computer and use it in GitHub Desktop.
@interface UIViewController (NibCells)
- (UITableViewCell *)loadTableViewCellFromNibNamed:(NSString *)nibName;
- (UITableViewCell *)loadReusableTableViewCellFromNibNamed:(NSString *)nibName;
@end
@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