Sizing of a UITableViewCell
Posted
by Xetius
on Stack Overflow
See other posts from Stack Overflow
or by Xetius
Published on 2010-05-12T20:25:49Z
Indexed on
2010/05/12
23:14 UTC
Read the original article
Hit count: 316
iphone
|uitableviewcell
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.
© Stack Overflow or respective owner