J'ai un en-tête de section personnalisé dans mon UITableView et je n'arrive pas à comprendre pourquoi ils apparaissent en dessous de UITableViewCell de la table. Voir les captures d'écran:L'en-tête de section personnalisée UITableView apparaît sous les cellules
C'est le code qui crée l'en-tête de section:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
return [LojaInfoHeaderView lojaInfoHeaderForSection:section withTitle:sectionTitle opened:[self sectionIsOpen:section] andDelegate:self];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return [LojaInfoHeaderView viewHeight];
}
Et sont insérés ou supprimés dans la cellule de la section lorsque l'utilisateur touche l'en-tête de section:
- (void)lojaInfoHeader:(LojaInfoHeaderView *)lojaInfoHeader sectionDidOpen:(NSInteger)section {
NSArray *indexPathsToInsert = [self indexPathsForSection:section];
[self setSection:section open:YES];
[_tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationTop];
}
- (void)lojaInfoHeader:(LojaInfoHeaderView *)lojaInfoHeader sectionDidClose:(NSInteger)section {
NSArray *indexPathsToDelete = [self indexPathsForSection:section];
[self setSection:section open:NO];
[_tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];
}
Comment puis-je faire apparaître l'en-tête de section au-dessus des cellules? Comment le réparer?
mise à jour pour montrer comment les choses sont créées
Ce sont les méthodes de classe que je utilise:
+ (CGFloat)viewHeight {
return 44.0;
}
+ (LojaInfoHeaderView *)lojaInfoHeaderForSection:(NSInteger)section withTitle:(NSString *)title opened:(BOOL)isOpen andDelegate:(id<LojaInfoHeaderDelegate>)delegate {
LojaInfoHeaderView *newHeader = [[[LojaInfoHeaderView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)] autorelease];
newHeader.section = section;
[newHeader setTitle:title];
newHeader.delegate = delegate;
[newHeader setOpen:isOpen animated:NO];
return newHeader;
}
Êtes-vous positif que '[LojaInfoHeaderView viewHeight]' est en fait de retour à la bonne hauteur et ne pas retourner 0? – imaginaryboy
Oui, l'implémentation est + (CGFloat) viewHeight {return 44.0; } // et 44 est la hauteur correcte. –
Hors sujet: comment obtenez-vous la barre de navigation et la barre d'outils et tous les boutons de la barre pour avoir cette belle couleur pourpre? Courez-vous sous iOS 4.x? Merci. (Pas sûr de la meilleure façon d'obtenir une réponse - à court de poster la question dirigée vers vous.) – westsider