gpt4 book ai didi

iphone - UITableview 部分标题不显示文本

转载 作者:行者123 更新时间:2023-12-01 17:27:14 25 4
gpt4 key购买 nike

我已将此代码添加到我的 UITableViewController 以返回灰色标题部分。

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
[headerView setBackgroundColor:[UIColor grayColor]];
return headerView;
}

但是现在这样做我看不到标题字符...我需要将其添加为 subview 吗?还是有另一种做事方式?

我有这些方法将标题和标题文本添加到 UITablView 但是当我使用上述方法时,我再也看不到它们了。
// Section headers
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [sectionLetterArray objectAtIndex:section];
}

// Section header titles
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return sectionLetterArray;
}

最佳答案

如果您创建自己的tableView:viewForHeaderInSection ,您必须创建 UILabel 或其他任何内容,并自己填写文本,例如:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
[headerView setBackgroundColor:[UIColor grayColor]];

// Add the label
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(kSectionTitleLeftMargin,
kSectionTitleTopMargin,
tableView.bounds.size.width - kSectionTitleLeftMargin - kSectionTitleRightMargin,
30.0 - kSectionTitleTopMargin - kSectionTitleBottomMargin)];

// do whatever headerLabel configuration you want here

headerLabel.text = [self tableView:tableView titleForHeaderInSection:section];
[headerView addSubview:headerLabel];

// Return the headerView
return headerView;
}

显然,将 headerLabel 更改为您想要的任何设置,但关键的关键信息是,如果您创建自己的 View ,则必须自己创建标签并填写文本。

关于iphone - UITableview 部分标题不显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10167554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com