Reputation: 1877
I m using this code for setting title and background color with UITableView but title is not shown?
- (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;
}
Please Help...
Upvotes: 1
Views: 2970
Reputation: 1918
Please change your code to this and ckeck only you have to implement viewForHeaderInSection method :
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSString *cellValue = @"";
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)] ;
[headerView setBackgroundColor:[UIColor brownColor]];
UILabel *lblContent = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, headerView.frame.size.width, headerView.frame.size.height)];
cellValue = [[arrSections objectAtIndex:0] valueForKey:@"CategoryName"];
lblContent.text = cellValue;
[headerView addSubview:lblContent];
return headerView;
}
Upvotes: 0
Reputation: 761
If I remember correctly, once you return something for viewForHeaderInSection
the value returned in titleForHeaderInSection
is no longer used. In viewForHeaderInSection
add a UILabel as a subview to headerView
and set the text to @"Contents"
Upvotes: 1