I am loading custom subclassed UITableViewCells from nib.
My view controller viewDidLoad method uses registerNib:forCellReuseIdentifier.
My view controller’s cellForRowAtIndexPath method uses dequeueReusableCellWithIdentifier to load the cell, but I never alloc/init the cell.
ViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tV registerNib:[UINib nibWithNibName:@"VersatileIntTFCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kTFInt];
self.tV.delegate=self;
self.tV.dataSource=self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Int TextField";
VersatileIntTFCell *cell = (VersatileIntTFCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
return cell;
}
The table view appears fine, and the cells appear fine.
Now, I am starting to write the subclasses of UITableViewCell. My subclasses each have some @property iVars (they are not IBOutlets). I would like to init these in the init method of the UITableViewCell subclass, but that doesn’t appear to ever get called. I can init them in the viewController’s cellForRowAtIndexPath but I want to avoid this. I want to do it in the UITableViewCell subclass. Is this possible? If so, how/where/when?
Override the
awakeFromNibmethod and put your code there rather than in the init.From the docs: