My UICollectionViewCell has a button in storyboard and setting the background image of number of buttons dynamically from document directory creating issues like some buttons background image doesn't refreshing, they hold old image even when i dismiss the controller and load again that controller, the issue still exist. How can solve this issue ?
In My 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;
}
In my custom 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