我正在创建一个自定义单元类,其中我在我的init方法中放置了不同类型的子视图,但是框架为CGRectZero。多个UITableViewCell类型实现
self.subTitleLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];[self.contentView addSubview:self.subTitleLabel];
self.scannedProductLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
[self.contentView addSubview:self.scannedProductLabel];
self.requestStatusLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
[self.contentView addSubview:self.requestStatusLabel];
在我的layoutSubviews方法中,我基于我的需要使用这些标签。就像,对于一种类型的单元格,我将使用第一个标签,对于其他类型将使用另一个标签。
if ([self.cellType isEqualToString:@"CustomerDetails"]) {
//self.productImageView.frame = CGRectMake(aContentRect.origin.x + kCellOffset, 0.0f, aTitleCellWidth , floorf(aHeight/4));
self.titleLabel.frame = CGRectMake(aContentRect.origin.x + kCellOffset, 0.0f, aTitleCellWidth , floorf(aHeight/2));
self.subTitleLabel.frame = CGRectMake(aContentRect.origin.x + kCellOffset, floorf(aHeight/2), aTitleCellWidth, floorf(aHeight/4));
self.requestStatusLabel.frame = CGRectMake(aContentRect.origin.x + kCellOffset, floorf((aHeight/2) + (aHeight/4)), aTitleCellWidth , floorf(aHeight/4));
}
我的问题是,从内存的角度来看这是一个好主意。就好像我的目的已经解决了,但我的自定义单元格对象包含在内存中但不可见的子视图。如果是,那么这种情况下的替代方法是什么。
这看起来很完美。谢谢。 – Abhinav 2010-11-18 04:31:49