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