It’s the first time I’m trying to use TableView in iOS and have an issue.
I have a tableview just with 2 sections and two rows in each section.
I have a situation that I need to add an image above my first section of my tableview(something like adding a sign on top of the TableView) , I tried to create/add a headerView for the first section section,and embed my image in it, but the problem is the image doesn’t let the title string for that section be shown. Do you think I need create & add (addsubview) another string as tile with UILable and append it to the headerView or is any other way to accomplish this?
The problem exists as long as I show the headerView for that section, as soon as I remove it, the section title will be appear.
Currently I do this in:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 0)
return headerView;
return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0)
return headerView.frame.size.height + self.rowHeight+28.0; //
return 30.0;//for other title header section
}
and my headerView allocated like this:
CGRect headerViewRect = CGRectMake(0.0, 10.0, frame.size.width -50 , self.rowHeight+50.0);
headerView = [[UIView alloc] initWithFrame:headerViewRect];
headerView.backgroundColor = [UIColor clearColor];
UIImageView *titleImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MyTitlePicture.png"]] autorelease];
CGRect imageViewRect = CGRectMake(0.0, 0.0, frame.size.width -100 , self.rowHeight+28.0);
titleImage.frame = imageViewRect;
titleImage.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[headerView addSubview:titleImage];
TIA,
Kamran
You you are replacing the default headerview, you are not adding to it. You need to program your UILabel and add that as a subview to your headerview.