Created
October 29, 2012 02:56
-
-
Save hfm/3971223 to your computer and use it in GitHub Desktop.
Snipped Customised UITableViewCell
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
// Inspired by http://stackoverflow.com/questions/540345/how-do-you-load-custom-uitableviewcells-from-xib-files | |
#import <UIKit/UIKit.h> | |
@interface BaseCell : UITableViewCell | |
/* Load Cell-Object from Nib-Name */ | |
+ (BaseCell*)cellFromNibNamed:(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
#import "BaseCell.h" | |
/* declaration of private property */ | |
@interface BaseCell() | |
@property (weak, nonatomic) IBOutlet HOGEHOGE *hogehoge; | |
@end | |
@implementation BaseCell | |
#pragma mark - Life Cycle | |
+ (BaseCell *)cellFromNibNamed:(NSString *)nibName | |
{ | |
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:NULL]; | |
NSEnumerator *nibEnumerator = [nibContents objectEnumerator]; | |
BaseCell *customCell = nil; | |
NSObject* nibItem = nil; | |
while ((nibItem = [nibEnumerator nextObject]) != nil) | |
{ | |
if ([nibItem isKindOfClass:[BaseCell class]]) | |
{ | |
customCell = (BaseCell *)nibItem; | |
break; // we have a winner | |
} | |
} | |
return customCell; | |
} | |
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier | |
{ | |
NSLog(@"%s",__func__); | |
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; | |
if (self) | |
{ | |
// Initialization code | |
} | |
return self; | |
} | |
- (void)setSelected:(BOOL)selected animated:(BOOL)animated | |
{ | |
[super setSelected:selected animated:animated]; | |
// Configure the view for the selected state | |
} | |
@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
#import <UIKit/UIKit.h> | |
@class BaseCell; | |
@interface BaseTableView : UITableView | |
@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
#import "BaseCell.h" | |
#import "BaseTableView.h" | |
@implementation BaseTableView | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
BaseCell *_basecell = [tableView dequeueReusableCellWithIdentifier:@"orgCell"]; | |
if (_basecell == nil) | |
{ | |
_basecell = (BaseCell *)[BaseCell cellFromNibNamed:@"Cell"]; | |
} | |
return _basecell; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment