添加iOS UITableView HeaderView(不是节标题) [英] Adding iOS UITableView HeaderView (not section header)

查看:123
本文介绍了添加iOS UITableView HeaderView(不是节标题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在联系人应用中添加一个表头(不是节头),例如:

I want to add a table header (not section headers) like in the contacts app for example:

与此相似 - 表格上方图片旁边的标签。

exactly like that - a label beside an image above of the table.

我希望所有视图都可以滚动,所以我不能把它放在桌子之外。

I want the all view be scrollable so I can't place those outside of the table.

我该怎么做?

推荐答案

UITableView 有一个 tableHeaderView 属性。将其设置为您想要的任何视图。

UITableView has a tableHeaderView property. Set that to whatever view you want up there.

使用新的 UIView 作为容器,添加文本标签和新的 UIView 的图像视图,然后将 tableHeaderView 设置为新视图。

Use a new UIView as a container, add a text label and an image view to that new UIView, then set tableHeaderView to the new view.

例如,在 UITableViewController 中:

-(void)viewDidLoad
{
     // ...
     UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
     [headerView addSubview:imageView];
     UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
     [headerView addSubview:labelView];
     self.tableView.tableHeaderView = headerView;
     [imageView release];
     [labelView release];
     [headerView release];
     // ...
} 

这篇关于添加iOS UITableView HeaderView(不是节标题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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