Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@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
You can’t perform that action at this time.