-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
}
Hi
I am very new in objective c..................
Please use following code & change the color of your UITableView header
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *tempHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,44)];
tempHeaderView.backgroundColor=[UIColor clearColor];
UILabel *tempHeaderLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,0,320,44)];
tempHeaderLabel.backgroundColor=[UIColor clearColor];
tempHeaderLabel.text=@"HEADER";
[tempHeaderView addSubView: tempHeaderLabel];
return tempHeaderView;
}
Beware that the view you return is not retained by the UITableView (OS 3.1.2 at least seems to display this problem). This leads to hard-to-find crashes that occur before execution gets to viewDidLoad.
The table view doesn't grab your views on demand as you would think. It requests them all, then requests them all again, and sometimes several more times, so generating them on every request is very inefficient.
You may try folowing: Header with two customized labels
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:
(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,
tableView.bounds.size.width, 22)];
NSString *dateStr = [[self.data allKeys] objectAtIndex:section];
CGFloat labelWidth = tableView.bounds.size.width / 2;
CGFloat padding = 5.0;
UILabel *labelOne = [[UILabel alloc] initWithFrame:CGRectMake
(padding, 0, (labelWidth - padding), 22)];
labelOne.backgroundColor = [UIColor clearColor];
labelOne.textAlignment = UITextAlignmentLeft;
labelOne.text = dateStr;
UILabel *labelTwo = [[UILabel alloc] initWithFrame:CGRectMake
(labelWidth, 0, (labelWidth - padding), 22)];
labelTwo.backgroundColor = [UIColor clearColor];
labelTwo.textAlignment = UITextAlignmentRight;
labelTwo.text = @"This is Label TWO";
[headerView addSubview:labelOne];
[headerView addSubview:labelTwo];
[labelOne release];
[labelTwo release];
return headerView;
}
Use tableView:viewForHeaderInSection: instead. That way you can configure a UILabel or whatever to your like (complete with font, transparency, color, etc), and the tableview will use that view as the header as opposed to the default view.