Posted By


athanhcong on 04/16/11

Tagged


Statistics


Viewed 114 times
Favorited by 0 user(s)

UITableViewCell+NibLoader


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. @implementation UITableViewCell (NibLoader)
  2.  
  3. #pragma mark Load cell nib
  4. + (id)loadViewWithNibName:(NSString *)nibName owner:(id)owner class:(Class)class {
  5. NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:nibName owner:owner options:nil];
  6. for (id currentObject in topLevelObjects) {
  7. if ([currentObject isKindOfClass:class]) {
  8. return currentObject;
  9. }
  10. }
  11. return nil;
  12. }
  13.  
  14. + (UITableViewCell *)loadCellForTableView:(UITableView *)tableView reuseIdentifier:(NSString *)cellIdentifier nibNamed:(NSString *)nibName {
  15. // Load custom cell
  16. // ref link: http://www.e-string.com/content/custom-uitableviewcells-interface-builder
  17. UITableViewCell *itemCell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  18. if (itemCell == nil) {
  19. itemCell = [self loadViewWithNibName:nibName owner:self class:[UITableViewCell class]];
  20. }
  21. return itemCell;
  22. }
  23.  
  24. @end
  25.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.