【发布时间】:2016-06-17 03:27:49
【问题描述】:
现在,我要生成一个titleview,它的高度对于tableHeaderView是可变的。所以我需要在tableview生成之前确认titleview的hegiht
//titleView
JMProductTitleView *titleView = [[JMProductTitleView alloc]initWithFrame:CGRectMake(0, 0, JMDeviceWidth, 300)];
titleView.delegate = self;
JMProductDetailModel *model = [JMPorductDetailTool createProductDetailModel];
titleView.model = model;
_titleView = titleView;
//
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, JMDeviceWidth, JMDeviceHeight) style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource = self;
tableView.tableHeaderView = titleView;
[self.view addSubview:tableView];
_tableView = tableView;
【问题讨论】:
-
您可以尝试使用 [self.view layoutIfNeeded]。它将强制视图布局所有约束。
-
太棒了!它对我有用。非常感谢。我使用过 [self.view setNeedsLayout],但没有用。我不知道为什么。你能告诉我它们之间的区别吗?
-
嗯,我不确定自己,除了我所知道的是,layoutIfNeeded 在内部调用所有强制 UI 进行设置的函数。转到此页面,它可能会清除一些东西stackoverflow.com/questions/2807137/… 另外我会将其添加为答案,因为它可以解决您的问题。
标签: ios objective-c constraints