J'ai une cellule dans laquelle j'ai deux étiquettes en haut, puis une vue au milieu et deux étiquettes en bas, c'est un graphique. J'ai codé en dur le nombre d'éléments car j'ai seulement besoin de 10-13 valeurs, apparemment tout va bien et les valeurs sont mises à jour et les sous-vues sont ajoutées dans la méthode de transfert cellForRowAt mais en défilant les valeurs des étiquettes apparaissent vides, et ce comportement est tout à fait anormal car défiler si 2ème et 3ème index devient vide puis sur défilement plus tard ils reviennent et 7ème oe 5 devient vide, comme ça puisqu'il n'y a aucun appel de service donc je n'appelle pas recharger des données. Cela me rend complètement folle je sais que cela a à voir avec quand la cellule est réutilisée, mais je ne sais pas pourquoi ou qu'est-ce que je fais mal, parce qu'au début, la valeur semble très bien.Collection Vue Cellule se comportant anormalement
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
TraingingGraphCollectionViewCell *cell = (TraingingGraphCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:[NSString stringWithFormat:@"TraingingGraphCollectionViewCell"] forIndexPath:indexPath];
if (indexPath.row == 0 || indexPath.row == 12) {
[cell initEmptyCell];
} else {
[cell initCellWithMaximumWeight:100 completedWeight:10*(int)indexPath.row maxRepititions:10 completedRepititions:(int)indexPath.row];
}
return cell;
}
Voici les méthodes appelées dans la méthode déléguée. `
-(void) initEmptyCell {
// [self setNeedsDisplay];
// back ground colour
self.backgroundColor = UIColorFromRGB(COLOUR_232323);
//hiding the labels
[self.completedWeightLabel setHidden:YES];
[self.completedRepititonsLabel setHidden:YES];
[self.dateLabel setHidden:YES];
[self.setLabel setHidden:YES];
}
C'est la deuxième méthode donnée ci-dessous
-(void) initCellWithMaximumWeight:(float)maxWeight
completedWeight:(float)completedWeight
maxRepititions:(int)maxRepititions
completedRepititions:(int)completedRepititions {
//reloading the content
//[self setNeedsDisplay];
// back ground colour
self.backgroundColor = UIColorFromRGB(COLOUR_232323);
// adding the weight bar
float weightPercentage = completedWeight/maxWeight;
if (weightPercentage > 1) {
weightPercentage = 1;
}
UIView *weightView = [[UIView alloc] initWithFrame:CGRectMake(20.0, self.graphView.frame.size.height - (self.graphView.frame.size.height * weightPercentage), 10.0, self.graphView.frame.size.height * weightPercentage)];
[weightView setBackgroundColor:UIColorFromRGB(COLOUR_E9280E)];
[self.graphView addSubview:weightView];
// adding the repititions bar
float repsPercentage = (float)completedRepititions/(float)maxRepititions;
if (repsPercentage > 1) {
repsPercentage = 1;
}
UIView *repsView = [[UIView alloc] initWithFrame:CGRectMake(35.0, self.graphView.frame.size.height - (self.graphView.frame.size.height * repsPercentage), 10.0, self.graphView.frame.size.height * repsPercentage)];
[repsView setBackgroundColor:UIColorFromRGB(COLOUR_97F619)];
[self.graphView addSubview:repsView];
//bottom view
[self.dateLabel setAttributedText:[NSString stringWithFormat:@"%@", [Utilities convertDateToString:[NSDate date] usingFormat:dd__MM_DATE_FORMAT forCulture:@"nl_NL"]] withFont:FontUsingMacro(LATO_BOLD_FONT_STRING, 12.0) kerining:1.3 color:UIColorFromRGB(COLOUR_FFFFFF)];
[self.setLabel setAttributedText:[NSString stringWithFormat:@"Set 01"] withFont:FontUsingMacro(LATO_BOLD_FONT_STRING, 12.0) kerining:1.3 color:UIColorFromRGB(COLOUR_808080)];
//top view
[self.completedWeightLabel setAttributedText:[NSString stringWithFormat:@"%.1f KG", completedWeight] withFont:FontUsingMacro(LATO_REGULAR_FONT_STRING, 12.0) kerining:1.3 color:UIColorFromRGB(COLOUR_E9280E)];
[self.completedRepititonsLabel setAttributedText:[NSString stringWithFormat:@"%d Reps", completedRepititions] withFont:FontUsingMacro(LATO_REGULAR_FONT_STRING, 12.0) kerining:1.3 color:UIColorFromRGB(COLOUR_97F619)];
}
difficile de trouver le problème sans code. –
J'ai ajouté le code, jetez-y un oeil. –
Dans initEmptyCell, vous masquez les choses. mais dans initCellWithMaximumWeight, vous ne l'avez pas masqué. Les cellules sont réutilisées (recyclées), vous devez donc les configurer pour tous les cas dans cellForRow. – GeneCode