0

Mon UICollectionViewCell a un bouton story-board et réglage de l'image de fond du nombre de boutons dynamiquement à partir du répertoire de documents qui crée des problèmes comme des boutons image de fond n'a pas rafraîchissant, ils tiennent vieille image même quand je rejette la contrôleur et charger à nouveau ce contrôleur, le problème existe toujours. Comment peut-on résoudre ce problème?réutilisable UICollectionViewCell ne rafraîchissant

Mon CollectionViewController:

- (NSString *)getBackgroundImage:(NSIndexPath *)indexPath { 

    NSArray *indexes = [self.allColors[indexPath.section] objectForKey:@"indexes"]; 

    return [NSString stringWithFormat:@"%@/%@/%@/combimeter_button/combimeter_%ld_%@@2x.png", [self.documentDirectory getDocumentsDirectory], _selectedCar, _selectedCar, (long)[indexes[indexPath.row] integerValue], [self getColorKey:indexPath.section]]; 
} 


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 

    CustomCollectionViewCell *cell = (CustomCollectionViewCell *) [collectionView dequeueReusableCellWithReuseIdentifier:@"CustomCell" forIndexPath:indexPath]; 

    cell.layer.borderWidth = 2.0f; 
    cell.layer.borderColor = [[self getBackgroundColor:indexPath.section] CGColor]; 
    [cell.cellButton setBackgroundImage:[UIImage imageNamed:[self getBackgroundImage:indexPath]] forState:UIControlStateNormal]; 
    [cell.cellButton addTarget:self action:@selector(combimeterButtonDidSelected:) forControlEvents:UIControlEventTouchUpInside]; 

    return cell; 
} 

Dans mon habitude CollectionView Cell:

@interface CustomCollectionViewCell : UICollectionViewCell 

@property (weak, nonatomic) IBOutlet UIButton *cellButton; 

@end 

@implementation CustomCollectionViewCell 

-(void)prepareForReuse { 
    NSLog(@"Is it possible to clear here ? but this method didn't call in my code"); 
} 

@end 
+0

poids est votre source de données pour la section et les lignes? – kaushal

+0

Je reçois les données du fichier plist – Nuibb

Répondre

2

Peut-être que le problème est imageNamed: met en cache l'image. Essayez d'utiliser imageWithContentsOfFile: à la place.

+0

Merci junk_key, tu m'as sauvé la vie ... :) – Nuibb

0

Essayez de supprimer toutes les vues précédentes avant de créer une nouvelle vue:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 

    CustomCollectionViewCell *cell = (CustomCollectionViewCell *) [collectionView dequeueReusableCellWithReuseIdentifier:@"CustomCell" forIndexPath:indexPath]; 

    for (UIView *subview in [cell subviews]) { 
     [subview removeFromSuperview]; 
    } 

    ... 
} 
+0

Non, cela ne fonctionne pas, dans ce cas, tous les boutons sont vides, pas d'image de fond montre. – Nuibb