我正在使用此代码通过 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/