如何在UITableView中添加节头

时间:2010-08-10 06:11:36

标签: iphone uitableview

如何在UITableView中添加节标题?

2 个答案:

答案 0 :(得分:26)

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

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

或者您可以使用UITableViewDelegate方法将自定义视图设置为标题:

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

实现这些的控制器需要是表视图的委托/数据源。

答案 1 :(得分:1)

使用UITableViewDelegate方法后:

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

您还必须使用UITableViewDelegate方法:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

显示标题。