简体   繁体   English

如何将子视图添加到UITableView的底部?

[英]How can I add a subview to the bottom of a UITableView?

I am using the EGOTableViewHeader class provided from: 我正在使用从以下位置提供的EGOTableViewHeader类:

http://www.drobnik.com/touch/2009/12/how-to-make-a-pull-to-reload-tableview-just-like-tweetie-2/ http://www.drobnik.com/touch/2009/12/how-to-make-a-pull-to-reload-tableview-just-like-tweetie-2/

I am able to display my view at the top of my UITableView: 我可以在UITableView的顶部显示我的视图:

refreshHeaderView = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, 320.0f, self.tableView.bounds.size.height)];
refreshHeaderView.backgroundColor = [UIColor colorWithRed:226.0/255.0 green:231.0/255.0 blue:237.0/255.0 alpha:1.0];
[self.tableView addSubview:refreshHeaderView];

How can I figure out the Y-Coordinate to show this view at the bottom of the last cell in my UITableView? 如何确定Y坐标以在UITableView的最后一个单元格的底部显示此视图?

Can you be a bit more specific? 你能更具体一点吗? Are there more cells that scroll into place? 还有更多滚动到位的单元格吗? I'm guessing your tableview has more cells than the screen real-estate provides, so do you want your view to come into place as the last cell is scrolled upward? 我猜您的表视图中的单元格多于房地产提供的屏幕,那么您是否希望在最后一个单元格向上滚动时视图就位?

Edit: Personally, the idea of figuring out content height on a table view is too messy, especially since you have to add the subview yourself, rather than have the UITableView manage it for you. 编辑:就个人而言,弄清表视图上的内容高度的想法太乱了,特别是因为您必须自己添加子视图,而不是让UITableView为您管理它。 There is a more elegant solution that works in my opinion: 在我看来,还有一个更优雅的解决方案有效:

Create an extra section (that doesn't have to have any rows associated with it). 创建一个额外的部分(不必与之关联任何行)。 Then implement the function 然后实现功能

tableView:viewForHeaderInSection:

Return the view you were meaning to add as a subview under your main table. 返回您要添加为主表下的子视图的视图。 That should do the trick. 这应该够了吧。

You can get the position of the very bottom of a tableView by using self.tableView.contentSize.height . 您可以使用self.tableView.contentSize.height获得tableView底部的位置。

So your code becomes 所以你的代码变成
refreshHeaderView = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, self.tableView.contentSize.height, 320.0f, self.tableView.bounds.size.height)];

Once you have the position just add the view to your tableView as you did with the previous one. 有了位置后,只需像上一个一样将视图添加到tableView中即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM