【问题标题】:iOS 7.1 doesn't allow Dynamic tableview HeightiOS 7.1 不允许动态 tableview 高度
【发布时间】:2015-09-25 17:35:25
【问题描述】:

我有一个 VC,我们称它为 "DetailsVC" 并带有一个 tableView,它会有不同高度的行。

"DetailsVC" 作为子视图添加到另一个名为 "MainVC"

的 VC

“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 及更高版本,但不适用于 iOS 7 或 7.1

tableview 的高度为零,根本不显示 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

【问题讨论】:

    标签: uitableview ios8 autolayout ios7.1 ios-autolayout


    【解决方案1】:

    我认为您只需要检查操作系统版本和低于 8 的操作系统版本,手动计算单元格的高度并将其返回。 另外,出于性能原因,对于 iOS 7,返回一个常量,或者干脆不实现 estimatedHeightForRowAtIndexPath

    Z.

    【讨论】:

      猜你喜欢
      • 2015-07-16
      • 2017-07-01
      • 1970-01-01
      • 2019-05-23
      • 2017-11-14
      • 2016-06-17
      • 2012-08-09
      • 2019-04-07
      • 1970-01-01
      相关资源
      最近更新 更多