获取静态UITableView的UITableViewHeaderFooterView

编程入门 行业动态 更新时间:2024-10-27 04:24:31
本文介绍了获取静态UITableView的UITableViewHeaderFooterView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个Storyboard,其中包含 UITableViewController 。表视图是静态的,包含两个部分。表视图完全在IB中设置(包括表视图部分的页眉和页脚文本) - 我没有在视图控制器中实现任何表视图委托方法。

I have a Storyboard which contains a UITableViewController. The table view is static and contains two sections. The table view was setup entirely in IB (including the header and footer text of the table view sections) - I have not implemented any table view delegate methods in my view controller.

如果我尝试获取对给定部分的 UITableViewHeaderFooterView 的引用,它总是返回nil。

If I attempt to get a reference to the UITableViewHeaderFooterView for a given section it always returns nil.

UITableViewHeaderFooterView* header =[self.tableView headerViewForSection:0];

当我运行应用程序时,我可以看到我在IB中设置的页眉和页脚文本,所以我知道那些观点在那里。我只是无法弄清楚如何以编程方式访问它们。

When I run the app I can see the header and footer text that I set in IB so I know those views are there. I just can't figure out how to access them programmatically.

任何帮助都将非常感激, CS

Any help would be much appreciated, CS

推荐答案

实际上,您需要指定表格页脚视图,并使用其委托将其传递给表格视图。

Actually you'll need to specify the table footer view, and pass it to the table view using its delegate.

例如,假设您已经定义了一个名为tableFooterView的IBOutlet UIView。 然后在下面的委托方法中,您可以将tableFooterView传递给表视图:

For example, suppose you have defined a IBOutlet UIView named tableFooterView. Then in the following delegate method, you can pass your tableFooterView to your table view:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section; // custom view for footer. will be adjusted to default or specified footer height { return self.tableFooterView; }

此外,您还需要实现以下方法来设置高度表页脚视图:

Also you'll need to implement the following method to set the height of the table footer view:

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return self.tableFooterView.frame.size.height; }

更多推荐

获取静态UITableView的UITableViewHeaderFooterView

本文发布于:2023-08-05 21:40:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1308213.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   UITableView   UITableViewHeaderFooterView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!