J'ai fait une UITableView
et définir le « délégué » et « source de données » et chaque fois que je l'appelle reloadData
, il va dans la méthode:viewForHeaderInSection: pas appelé quand reloadData: est appelé
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.headersList count];
}
Et la méthode:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
SectionInfo *headerInfo = (self.headerInfoArray)[section];
NSInteger numOfObjectsInSection = [[headerInfo.list objectsInList] count];
return headerInfo.open ? numOfObjectsInSection : 0;
}
Puis s'arrête! il ne va pas dans la méthode ViewForHeaderInSection:
. J'ai également mis en œuvre la méthode:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return SECTION_HEADER_HEIGHT;
}
- Sachant que j'utiliser la fonction de section d'ouverture/fermeture! donc au début toutes les sections sont fermées et le nombre de lignes dans chacune est 0 mais le nombre de sections retournées est correct (lorsqu'une section est ouverte, le nombre de lignes est mis à jour). La seule façon pour cela d'afficher les vues d'en-tête est d'attendre un certain temps jusqu'à ce qu'il soit rechargé automatiquement! ou je balaye vers le haut ou vers le bas!
La méthode viewForHeaderInSection
:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UISectionHeaderView *sectionHeaderView = [[UISectionHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, SECTION_HEADER_HEIGHT)];
SectionInfo *sectionInfo = (self.headerInfoArray)[section];
sectionHeaderView.open = sectionInfo.open;
sectionInfo.headerView = sectionHeaderView;
sectionHeaderView.titleLabel.text = [NSString stringWithFormat:@"%@ (%lu)",sectionInfo.list.title, (unsigned long)[sectionInfo.list.objectsInList count]];
sectionHeaderView.section = section;
sectionHeaderView.delegate = self;
return sectionHeaderView;
}
Je suppose que vous définissez votre classe à la fois comme 'dataSource' et le' delegate' de votre 'UITableView', non? – dasblinkenlight
Vous pouvez également utiliser les méthodes de la section reload pour essayer une approche différente. Montrez-nous vos rappels de sources de données en vue de l'en-tête et du pied de page pour voir s'il y a un problème. – J2theC
yah, il n'y a rien de mal avec la source de données et déléguer. Ce problème se produit uniquement lorsque toutes les sections sont fermées. – a7md