When exactly does layoutSubviews
get called on a custom UITableViewCell
in a UITableViewCells
cellForRowAtIndexPath
method? Below, I need layoutSubviews
to be called AFTER I set the FiltersTableViewCellItem
property. Do I have this set up correctly? I'd like to be able to use layoutSubviews
because I heard it's better for performance.
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"FiltersTableViewCell";
FiltersTableViewCell *filtersTableViewCell = [[self dequeueReusableCellWithIdentifier:cellIdentifier] retain];
FiltersTableViewCellItem *filtersTableViewCellItem = [[self.filtersTableViewCellItems objectAtIndex:[indexPath row]] retain];
if (!filtersTableViewCell)
{
filtersTableViewCell = [[FiltersTableViewCell alloc] initWithFiltersTableViewCellItem:filtersTableViewCellItem];
filtersTableViewCell.delegate = self;
}
else
{
filtersTableViewCell.filtersTableViewCellItem = filtersTableViewCellItem;
}
return [filtersTableViewCell autorelease];
}
layoutSubviews
is called at some point after tableView:willDisplayCell:
, which is called after tableView:cellForRowAtIndexPath:
. You can verify this by setting breakpoints in the relevant methods and seeing the order in which they get hit. For example, set a breakpoint at the end of tableView:cellForRowAtIndexPath:
. Then add the following method to FiltersTableViewCell
- (void)layoutSubviews
{
[super layoutSubviews];
}
and set a breakpoint there. Then run the app and see what happens.
Try calling setNeedsLayout after setting your item.
filtersTableViewCell.filtersTableViewCellItem = filtersTableViewCellItem;
[filtersTableViewCell setNeedsLayout];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With