如何将 UIView 放入 UITableView [英] How to put a UIView in a UITableView

查看:29
本文介绍了如何将 UIView 放入 UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableView,我试图在表格中的单元格上方放置一个图表.我有一个扩展 UIView 的GraphView",我想把它放在我的表中.我该怎么做?

I have a UITableView and I'm trying to put a graph in my table above the cells. I have a "GraphView" that I've made that extends UIView and I'd like to put it in my table. How can I do this?

推荐答案

您可以将其设置为 tableHeaderView,如下所示:

You could set it as the tableHeaderView, like so:

UITableView *tv = ...;

tv.tableHeaderView = yourView;

或者使用 Interface Builder,更简单.

or using Interface Builder, even easier.

阅读UITableViewDataSourceUITableViewDelegate 的文档以了解有关这些功能的更多信息:

Read the documentation of UITableViewDataSource and UITableViewDelegate to find out more about these functions:

 -(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
 -(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section

然后您应该为每个部分返回一个 UIView.(记住 autorelease 它们,如果它们不是静态分配的!)

You should then return a UIView per section. (remember to autorelease them, if they are not statically allocated!)

这篇关于如何将 UIView 放入 UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆