Я изменил 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;
}