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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You could set it as the tableHeaderView
, like so:
UITableView *tv = ...;
tv.tableHeaderView = yourView;
or using Interface Builder, even easier.
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
You should then return a UIView
per section. (remember to autorelease
them, if they are not statically allocated!)