如何在UITableView中添加一个分组标题

10

我该如何在UITableView中添加一个section标题?

2个回答

24

如果你只需要节标题,可以使用UITableViewDataSource方法:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

或者你可以使用UITableViewDelegate方法将自定义视图设置为表头:

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

实现这些功能的控制器需要成为您表视图的委托/数据源。


1
使用UITableViewDelegate方法后: - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
您还必须使用UITableViewDelegate方法: - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
以显示页眉。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接