Sizing of a UITableViewCell
- by Xetius
I have created a UITableViewCell derived class which resizes itself to display at an indentation level. I have tried setting indentationLevel and indentationWidth using the following in the ViewControllers cellForRowAtIndexPath:
cell.indentationLevel = [[item objectForKey:@"indent"] intValue];
cell.indentationWidth = CELL_INDENT_SIZE;
This in itself does not indent the cell, so I am using the following layoutSubviews in the UITableViewCell:
-(void)layoutSubviews {
CGFloat indentSize = (self.indentationLevel - 1) * self.indentationWidth;
CGRect r = containerView.frame;
containerView.frame = CGRectMake (r.origin.x + indentSize, r.origin.y, r.size.width - indentSize, r.size.height);
DLog(@"frameRect : %f, %f, %f, %f, %f",indentSize, r.origin.x, r.origin.y, r.size.width, r.size.height);
[super layoutSubviews];
}
This works fine for the initial layout, but when the cell is selected, it recalculates itself from the new dimensions and effectively shrinks the cell every time it is selected.
How can I resize this cell so that it doesn't keep changing the layout.