Ho problemi a animare un'intestazione di sezione UITableView personalizzata.
L'obiettivo era creare sezioni pieghevoli.
Quando tocco l'intestazione personalizzata la prima volta che si anima come previsto, tuttavia, ogni volta dopo, lascia un duplicato nella posizione originale e ne anima un'altra.UITableView Intestazione sezione personalizzata, duplicato problema
Esempio Image:
alt text http://img35.imageshack.us/img35/4018/screenshot2010022722565.png alt text http://img291.imageshack.us/img291/8287/screenshot2010022723035.png
mio header personalizzato:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView* customView = [[[UIView alloc]initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)]autorelease];
customView.backgroundColor = [UIColor lightGrayColor];
UILabel * headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor darkGrayColor];
headerLabel.font = [UIFont boldSystemFontOfSize:16];
headerLabel.frame = CGRectMake(10, 7, 260.0, 44.0);
headerLabel.textAlignment = UITextAlignmentCenter;
NSDictionary *dictionary = [self.data objectAtIndex:section];
headerLabel.text = [dictionary objectForKey:@"Title"];
[customView addSubview:headerLabel];
// add button to right corner of section
UIButton* headerButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 320, 44)];
headerButton.center = CGPointMake(160.0, 22.0);
headerButton.backgroundColor = [UIColor clearColor];
headerButton.tag = section;
[headerButton addTarget:self action:@selector(expandSection:) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:headerButton];
return customView;
}
mio Animazione Metodo:
- (void) expandSection:(id)sender {
if (expandedSection == [sender tag]) {
expandedSection = -1;
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:[sender tag]] withRowAnimation:UITableViewRowAnimationNone];
}else if (expandedSection == -1){
expandedSection = [sender tag];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:[sender tag]] withRowAnimation:UITableViewRowAnimationNone];
}else{
[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:expandedSection] withRowAnimation:UITableViewRowAnimationNone];
expandedSection = [sender tag];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:[sender tag]] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
}
//[self.tableView reloadData];
}
Io non sono esattamente sicuro che cosa sta succedendo, ma la le istanze suggeriscono che ho bisogno di dealoc qualcosa. Ho provato alcune cose ma non riesco a capirlo. Qualunque aiuto su questo sarebbe fantastico!
Modifica: Credo che il problema è che reloadSections sta causando l'istanza della vista personalizzata. Non riesco a rilasciare la vista perché ne ho bisogno come riferimento per fare l'aggiornamento per l'animazione. Qualche idea su cosa posso fare per risolvere questo problema?
Grazie a questo risolve un problema correlato in cui volevo produrre un effetto animato di eliminazione/inserimento delle stesse righe, dove, senza prima chiamare 'reloadData', avrebbe solo animato le eliminazioni, ma non animato gli inserti. Era un problema molto strano. – Jeremy
Buon modo ... + 1 per te uomo – Sabby