2015-09-25 82 views
0

我有一个VC让我们叫它“DetailsVC”与一个tableView将有不同高度的行。iOS 7.1不允许动态tableview高度

“DetailsVC”被添加作为子视图到另一个VC称为“MainVC”

“DetailsVC”

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.automaticallyAdjustsScrollViewInsets = YES; 
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier]; 
    self.tableView.rowHeight = UITableViewAutomaticDimension; 

} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    [self.navigationController setNavigationBarHidden:NO animated:animated]; 
} 

- (void)viewDidLayoutSubviews 
{ 
    [super viewDidLayoutSubviews]; 
    self.tableViewHeightConstraint.constant = self.tableView.contentSize.height; 
    [self.tableView needsUpdateConstraints]; 

    CGFloat containerHeight = CGRectGetHeight(self.tableView.bounds) + self.addressLabelHeightConstraint.constant; 
    [self.tableViewdelegate punchDetailsController:self didUpdateTableViewWithHeight:containerHeight]; 
    [self.contentView layoutIfNeeded]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    return UITableViewAutomaticDimension; 
} 

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    return UITableViewAutomaticDimension; 
} 

这非常适用在IOS 8及以上和没有按'T在iOS 7或7.1中工作

桌面视图的高度出现为ZERO,并且doens不会显示tableview。

我明白了“UITableViewAutomaticDimension”是的iOS 8的一部分,不适用于iOS 7

我应该使用什么其他的方法来对两者的iOS 7和iOS 8

我的问题是类似的工作https://stackoverflow.com/questions/29425782/ios7-0-and-ios-7-1-doesnt-honor-dynamic-tableview-height

回答

0

我想你只需要检查操作系统版本和低于8,手动计算单元格的高度并返回它。 此外,出于性能的考虑,针对iOS 7返回一个常量,或者只是不实现estimatedHeightForRowAtIndexPath

Z.