Adding subviews to UITableViewCell's contentView and autoresizing behavior
Adding subviews to UITableViewCell's contentView and autoresizing behavior
- Subject: Adding subviews to UITableViewCell's contentView and autoresizing behavior
- From: Ray <email@hidden>
- Date: Thu, 03 Mar 2011 15:39:41 +0900
Hi! First post to the list, please be gentle ;)
Small question: when I add a subview to the contentView of a UITableViewCell, the rendered width of the subview's frame will be different, depending on whether I set the autoresizingMask in combination with an accessoryView. So, when I set up a clean test project using the usual UITableViewController, make its TableView visible etc. and then use this example code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UIView *testView;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
testView = [[[UIView alloc] initWithFrame:CGRectMake(10.0, 10.0, 226.0, 12.0)] autorelease];
// testView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
testView.backgroundColor = [UIColor redColor];
[cell.contentView addSubview:testView];
UIView *testHolder = [[[UIView alloc] initWithFrame:CGRectIntegral(CGRectMake(0.0, 0.0, 64.0, 32.0))] autorelease];
testHolder.backgroundColor = [UIColor greenColor];
cell.accessoryView = testHolder;
}
return cell;
}
the actual rendered width of the testView will be smaller (in this case 70 points I think it was) when I uncomment the UIViewAutoresizingFlexibleWidth bit. There will be no difference when I don't use a cell.accessoryView...
Is this expected behavior? Does it have to do with how the cell layouts its subviews depending on the use of an accessoryView? I couldn't find this in the documentation nor the list archive, so if anyone could enlighten me, much appreciated! I would also be interested in workarounds...
Thanks!
- Ray.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden