2015-09-25 62 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.