Au lieu d'utiliser la méthode normale
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
Vous voulez mettre en œuvre celui-ci:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Comme vous pouvez le voir, le second retourne un UIView au lieu de simplement la chaîne pour le texte. Vous pouvez donc personnaliser votre propre vue (avec des étiquettes, etc.) et la renvoyer.
Voici un exemple de la façon dont vous pourriez faire (être mis en œuvre dans la méthode ci-dessus):
// create the parent view that will hold header Label
UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(10,0,300,60)] autorelease];
// create image object
UIImage *myImage = [UIImage imageNamed:@"someimage.png"];;
// create the label objects
UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.font = [UIFont boldSystemFontOfSize:18];
headerLabel.frame = CGRectMake(70,18,200,20);
headerLabel.text = @"Some Text";
headerLabel.textColor = [UIColor redColor];
UILabel *detailLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
detailLabel.backgroundColor = [UIColor clearColor];
detailLabel.textColor = [UIColor darkGrayColor];
detailLabel.text = @"Some detail text";
detailLabel.font = [UIFont systemFontOfSize:12];
detailLabel.frame = CGRectMake(70,33,230,25);
// create the imageView with the image in it
UIImageView *imageView = [[[UIImageView alloc] initWithImage:myImage] autorelease];
imageView.frame = CGRectMake(10,10,50,50);
[customView addSubview:imageView];
[customView addSubview:headerLabel];
[customView addSubview:detailLabel];
return customView;
espoir qui aide
+1 pour la belle question. :) – mAc