Altezza tableHeaderView sembra essere 0
-
20-09-2019 - |
Domanda
Ho cercato di ignorare il secondo tableHeaderView. Ma sembra che l'altezza di esso nel metodo sembra heightForHeaderInSection a 0. Non posso spiegarlo, devo metterlo in un'iVar perché nel viewForHeaderInSection posso impostare la visualizzazione senza problemi.
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if(section == 0)
return @"Adding a new list";
else
return @"Other lists";
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if(section == 0) {
return tableView.tableHeaderView;
} else {
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)] autorelease];
view.backgroundColor = [UIColor redColor];
return view;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(section == 0)
return tableView.tableHeaderView.frame.size.height;
else
return 30;
}
Soluzione
Penso che si sta confondendo l'intestazione della tabella e l'intestazione per ogni sezione, sono diversi. Non c'è un "secondo tableHeaderView", un UITableView
ha una tableHeaderView
e poi dipende dalle viewForHeaderInSection
e heightForHeaderInSection
metodi per posizionare le viste di intestazione personalizzate per ogni sezione, in caso contrario è sufficiente utilizzare titleForHeaderInSection
per inserire il testo lì.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow