ios - 如何在其他 View 生成之前完成一个 View 约束

标签 ios objective-c constraints

现在,我要生成一个 titleview,它的高度对于 tableHeaderView 是可变的。所以我需要在生成 tableview 之前确认 titleview 的高度

//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]。它将强制 View 布局所有约束。

关于ios - 如何在其他 View 生成之前完成一个 View 约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37872636/

相关文章:

java - 数组约束满足

android - Android 中是否有与 NotificationListenerService 等效的 iOS?

ios - TableView 从 : numberOfRowsInSection 中的最后一部分开始

objective-c - 关于 NSNotification Center 的 2 个速记

ios - Objective-C:淡化 GUI

mysql - 检查 mysql 不工作(没有错误)

ios - 如何在 iOS 上检测双核 CPU?

android - 用于繁重计算的 WebAssembly + WebView + Javascript 接口(interface)?

c++ - 如何在 Objective-C 中验证 JSON Schema?

java fx : Where is the constraint property saved when using GridPane. setRowIndex(...);