问题描述
我无法调整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)Build and Go。一切正常。
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?
有任何人能够这样做吗?
Have anyone able to do this?
感谢
iMe
推荐答案
FYI:我已经通过修改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的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!