Skip to content

Instantly share code, notes, and snippets.

@serhatsezer
Created March 24, 2015 12:21
Show Gist options
  • Save serhatsezer/1361536cd27d0449a574 to your computer and use it in GitHub Desktop.
Save serhatsezer/1361536cd27d0449a574 to your computer and use it in GitHub Desktop.
UITableview lazy cell instatiation
@interface UserDetailViewController()
@property(strong, nonatomic) MyCustomCell *customCell;
@end
@implementation UserDetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Load Xib file...
// Custom cell
[self.tableView registerNib:[UINib nibWithNibName:[MyCustomCell defaultIdentifier] bundle:nil]
forCellReuseIdentifier:[MyCustomCell defaultIdentifier]];
}
...
....
// Tableview delegate method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 0) {
return self.myCustomCell;
}
...
...
...
}
- (MyCustomCell *) customCell {
if(!_customCell) {
_customCell = [self.tableView dequeueReusableCellWithIdentifier:[MyCustomCell defaultIdentifier]
forIndexPath:[self customCellIndexPath]];
}
return _customCell;
}
- (NSIndexPath *)customCellIndexPath {
return [NSIndexPath indexPathForRow:0 inSection:0];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment