Ios UITableViewCell';s的宽度和高度始终为320和44
我为我的蹩脚英语感到抱歉。 名为“A”的单元格包含子表视图;“A”为正常值,但子单元的frame.size始终为(320,44)。 显示代码Ios UITableViewCell';s的宽度和高度始终为320和44,ios,objective-c,iphone,uitableview,Ios,Objective C,Iphone,Uitableview,我为我的蹩脚英语感到抱歉。 名为“A”的单元格包含子表视图;“A”为正常值,但子单元的frame.size始终为(320,44)。 显示代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* cellID = @"OrderViewControllerCellID"; OrderTable
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* cellID = @"OrderViewControllerCellID";
OrderTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (nil == cell) {
cell = [[OrderTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
OrderCellModel* model = self.orderDataSourceArray[indexPath.row];
cell.model = model;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.backgroundColor = [UIColor yellowColor];
return cell;
}
“A”单元内容视图
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
_productsArray = [[NSMutableArray alloc] init];
_productsTableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
_productsTableView.delegate = self;
_productsTableView.dataSource = self;
[self.contentView addSubview:_productsTableView];
_productsTableView.scrollEnabled = NO;
}
return self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* cellID = @"OrderTableViewSubCellID";
OrderSubTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[OrderSubTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
OrderProductModel* model = _productsArray[indexPath.row];
cell.model = model;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _productsArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return transForHeight(86.f);
}
谢谢你看我的问题。
我再次为我的小英语感到抱歉。
initWithStyle
始终返回高度为44的单元格,除非在子类中覆盖它。您应该在代理方法中更改高度。默认单元格高度为44.0
。您需要重写heightforrowtaindexpath
方法。是。它总是返回44号单元格的高度。如果要更改,请实现heightforrowatindexpath方法。我认为单元格内容视图的自动布局设置不正确;看到你的截图,似乎连自动调整大小的掩码都没有设置。谢谢你的回答,我会尝试你的建议。如果这个答案有帮助,请选中复选标记,将其作为正确答案接受。谢谢