UITableViewCell的宽度和高度始终为320和44

时间:2016-01-07 10:43:39

标签: ios objective-c iphone uitableview

对不起我粗鲁的英语我很抱歉。 名为'A'的单元格包含subTableView;'A'是正常的,但subCell的frame.size始终为(320,44)。 显示代码。

- (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'cell contentView

- (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);
}

enter image description here

谢谢你看我的问题。 我再次为我的小英语感到抱歉。

2 个答案:

答案 0 :(得分:0)

initWithStyle allways返回高度为44的单元格,除非您在子类中覆盖它。您应该在委托方法中更改高度。

答案 1 :(得分:-2)

默认单元格高度为44.0。您需要覆盖heightforrowatindexpath方法。