我已经更改了我的 tableviews 部分的 backgroundColor/backgroundImage。
我正在使用普通的tableView。不用担心,使用此代码可以毫无问题地工作:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 728, 40)] autorelease];
sectionView.backgroundColor = [UIColor greenColor];
//For using an image use this:
//sectionView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"whiteBackground.png"]];
return sectionView;
}
现在的问题是,章节标题不见了。
我正在使用以下代码设置该部分的标题:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]){
return @"";
} else {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo name];
}
}
如果我不使用,我会得到章节标题
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
需要你的帮助。
非常感谢。
编辑1:
感谢 Mutix:
就我而言,答案是:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 728, 20)] autorelease];
sectionView.backgroundColor = [UIColor greenColor];
//sectionView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"whiteBackground.png"]];
//Add label to view
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 728, 20)];
titleLabel.backgroundColor = [UIColor clearColor];
//section Title
if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]){
titleLabel.text = @"";
} else {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
titleLabel.text = [sectionInfo name];
}
[sectionView addSubview:titleLabel];
[titleLabel release];
return sectionView;
}