gpt4 book ai didi

ios - 可重用的 UICollectionViewCell 不刷新

转载 作者:行者123 更新时间:2023-11-28 21:15:02 24 4
gpt4 key购买 nike

我的 UICollectionViewCell 在 Storyboard 中有一个按钮,并从文档目录中动态设置按钮数量的背景图像,从而产生一些问题,例如某些按钮背景图像不刷新,即使我关闭 Controller 并再次加载该 Controller ,它们也会保留旧图像,问题依然存在。如何解决这个问题?

在我的 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;
}

在我的自定义 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

最佳答案

也许问题在于 imageNamed: 缓存了图像。尝试改用 imageWithContentsOfFile:

关于ios - 可重用的 UICollectionViewCell 不刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41584119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com