2016-01-07 60 views
0

对不起我的劣质英语。 名为'A'的单元格包含subTableView;'A'是正常的,但subCell的frame.size总是(320,44)。 显示代码。UITableViewCell的宽度和高度始终为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内容查看

- (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

谢谢你看我的问题。 我很抱歉我的小英文了。

+0

是的。它总是返回单元格44的高度。如果你想改变然后实现heightforrowatindexpath方法。 –

+0

我不认为_auto-layout_已经为您的单元格的内容视图正确设置;看到你的截图,似乎甚至没有设置_autoresize-mask_。 – holex

回答

0

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

+0

谢谢您的回答,我会尝试您的建议。 –

+0

如果此答案有帮助,请选择复选标记以接受此答案为正确答案。谢谢! –

-1

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

+0

非常感谢! –