ios - UITableView 标题中的标题未显示?

标签 ios uitableview

我正在使用此代码通过 UITableView 设置标题和背景颜色,但未显示标题?

- (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section
{
    return @"Contents";
}

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)] autorelease];
    [headerView setBackgroundColor:[UIColor brownColor]];
    [self.view sendSubviewToBack:headerView];

    return headerView;
}

请帮忙...

最佳答案

如果我没记错的话,一旦你为 viewForHeaderInSection 返回了一些东西,在 titleForHeaderInSection 中返回的值就不再被使用。在 viewForHeaderInSection 中添加一个 UILabel 作为 subview 到 headerView 并将文本设置为 @"Contents"

关于ios - UITableView 标题中的标题未显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3769658/

相关文章:

swift - 编辑按钮没有任何功能,单元格左侧没有带减号的红色圆圈

objective-c - 单击按钮后如何显示 TableView 单元格值?

ios - 导航 Controller

ios - 我是否需要 Mac 来开发 Azure Xamarin.iOS 应用程序?

ios - 如何在 UITableViewController 中引用自定义 UIView 的 subview 按钮

ios - 如何将 ViewController 的 subview 转换为另一个 ViewController 的 subview

iOS - UITableView - 取消删除行 - 按钮动画仅适用于附件 View

ios - UIButton 不听内容模式设置?

ios - 用NSTimer替换usleep吗?

ios - 特定实体的 RestKit 映射