问题描述
我在调整 tableHeaderView 的大小时遇到问题.简单的不行.
I'm having trouble resizing a tableHeaderView. It simple doesn't work.
1) 创建一个 UITableView 和 UIView (100 x 320 px);
1) Create a UITableView and UIView (100 x 320 px);
2) 设置UIView为UITableView的tableHeaderView;
2) Set the UIView as tableHeaderView of the UITableView;
3) 构建并运行.一切正常.
3) Build and Go. Everything is ok.
现在,我想调整 tableHeaderView 的大小,所以我在 viewDidLoad 中添加了以下代码:
Now, I want to resizing the tableHeaderView, so I add this code in viewDidLoad:
self.tableView.autoresizesSubviews = YES;
self.tableView.tableHeaderView = myHeaderView;
self.tableView.tableFooterView = myFooterView;
CGRect newFrame = self.tableView.tableHeaderView.frame;
newFrame.size.height = newFrame.size.height + 100;
self.tableView.tableHeaderView.frame = newFrame;
tableHeaderView的高度应该出现200,但出现100.
The height of the tableHeaderView should appear with 200, but appears with 100.
如果我写:
self.tableView.autoresizesSubviews = YES;
CGRect newFrame = myHeaderView.frame;
newFrame.size.height = newFrame.size.height + 100;
myHeaderView.frame = newFrame;
self.tableView.tableHeaderView = myHeaderView;
self.tableView.tableFooterView = myFooterView;
然后它以 200 的高度开始,如我所愿.但我希望能够在运行时修改它.
Then it starts with 200 of height, as I want. But I want to be able to modify it in runtime.
我也试过这个,但没有成功:
I've also tried this, without success:
self.tableView.autoresizesSubviews = YES;
self.tableView.tableHeaderView = myHeaderView;
self.tableView.tableFooterView = myFooterView;
CGRect newFrame = self.tableView.tableHeaderView.frame;
newFrame.size.height = newFrame.size.height + 100;
self.tableView.tableHeaderView.frame = newFrame;
[self.tableView.tableHeaderView setNeedsLayout];
[self.tableView.tableHeaderView setNeedsDisplay];
[self.tableView setNeedsLayout];
[self.tableView setNeedsDisplay];
这里的重点是:我们如何在运行时调整 tableHeaderView 的大小???
有人能做到吗?
谢谢
iMe
推荐答案
仅供参考:我已经通过修改 tableHeaderView 并重新设置它来使其工作.在这种情况下,我会在 UIWebView 子视图加载完成后调整 tableHeaderView 的大小.
FYI: I've gotten this to work by modifying the tableHeaderView and re-setting it. In this case, i'm adjusting the size of the tableHeaderView when the UIWebView subview has finished loading.
[webView sizeToFit];
CGRect newFrame = headerView.frame;
newFrame.size.height = newFrame.size.height + webView.frame.size.height;
headerView.frame = newFrame;
[self.tableView setTableHeaderView:headerView];
这篇关于如何调整 UITableView 的 tableHeaderView 的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!