我正在尝试在我的 TableView 中实现自定义 UITableVieCell。在单元格中有两个子视图,它们的属性错误。
这是我的 tableView:cellForRowAtIndexPath: :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
ListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[ListCell alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 70.0f)];
}
return cell;
}
以下是我的自定义 Cell ListCell 中的两个 init 方法:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.frame = frame;
cellBack = [[ListCellBack alloc] initWithFrame:CGRectMake(0.0, 0.0, frame.size.width, frame.size.height)];
cellFront = [[ListCellFront alloc] initWithFrame:CGRectMake(0.0, 0.0, frame.size.width, frame.size.height)];
[self.contentView addSubview:cellBack];
[self.contentView addSubview:cellFront];
slideEnabled = YES;
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self) {
}
return self;
}
这就是解决方案:
这就是我的目标:
所以我的自定义 Cell 的两个子视图得到了错误的帧数。我为此苦苦挣扎了好几个小时!
提前致谢!