UITableView:以编程方式更改页脚视图的大小不起作用
我的表视图的页脚是一个显示用户的一些推文的视图,因此在收到推文之前我不知道它的高度,我创建了一个 FooterViewController
,它有一个方法 refreshTweets
>,我将其添加到 viewDidLoad
中:
FooterViewController *controller = [[FooterViewController alloc] initWithNibName...];
[[self tableView] setFooterView:[controller view]];
[controller refreshTweets];
在 refreshTweets
方法中,我读取推文并计算总高度,并重置视图(页脚)的高度:
self.view.frame = newFrame;
但它没有有道理,页脚的高度仍然是我在 Interface Builder 中设置的高度,是否缺少任何内容或有任何其他方法可以做到这一点?
谢谢!
编辑: 我可以在界面生成器中将视图的大小更改为足够小,并且在计算推文高度并设置view.frame后它将被放大,但表视图仍然认为其页脚具有先前的高度,即多余的空间在外面表格视图的视图,只有向上拖动表格才能看到它。
My table view's footer is a view that shows some tweets from a user, so I do not know its height until I got the tweets, I created a FooterViewController
that has a method refreshTweets
, I add it in viewDidLoad
:
FooterViewController *controller = [[FooterViewController alloc] initWithNibName...];
[[self tableView] setFooterView:[controller view]];
[controller refreshTweets];
in refreshTweets
method, I read tweets and calculate the total height, and reset view(the footer)'s height:
self.view.frame = newFrame;
but it does not make sense, the footer's height is still the height I set in Interface Builder, is there anything missing or any alternative way of doing this?
Thanks!
edit:
I can change the view's size to be small enough in interface builder, and it will be enlarged after calculating tweets' height and setting view.frame, but the table view still thinks its footer has previous height, that is, the extra space is outside of the tableview and I can only see it if I drag the table up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将页脚视图重新分配给表格。该表将识别出它有一个新的页脚,并重新执行所需的布局以获得正确的页脚大小。
Re-assign your footer view to the table. The table will recognize it has a new footer and re-do whatever layout needs to occur for the proper size of the footer.
为了改变页脚视图的框架,这里有一个简单的调整:-
在 Swift 中:-
In order to change the frame of footer view here is the simple tweak:-
In Swift:-