gpt4 book ai didi

ios - 停止在 Collection View 中重新加载

转载 作者:行者123 更新时间:2023-11-29 00:36:46 25 4
gpt4 key购买 nike

我是 Objective-c 的新手。我正在处理 Collection View 。在我的 Collection View 中,我的数组中有数据列表。当我将数组中的数据加载到集合单元格中时,它没有按照数组顺序显示。当我滚动时,单元格值不断变化。

这是我的代码。

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return myObject.count;
}

- (UIView *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
if([statusfield isEqualToString:@"13"])
{
[cell.mySegmentedControl setTitle:@"SEND TO ADMIN" forSegmentAtIndex:0];
[cell.mySegmentedControl setTitle:@"EVALUATE" forSegmentAtIndex:1];
}
else if([statusfield isEqualToString:@"5"])
{
[cell.mySegmentedControl setEnabled:NO forSegmentAtIndex:0];
[cell.mySegmentedControl setEnabled:NO forSegmentAtIndex:1];
}

else if([statusfield isEqualToString: @"1"])
{
[cell.mySegmentedControl setTitle:@"ACCEPT" forSegmentAtIndex:0];
[cell.mySegmentedControl setTitle:@"REJECT" forSegmentAtIndex:1];
}
else if([statusfield isEqualToString:@"3"])
{
[cell.mySegmentedControl setTitle:@"VIEW" forSegmentAtIndex:0];
[cell.mySegmentedControl setSelectedSegmentIndex:UISegmentedControlNoSegment];
}
return cell;
}

分段控件值基于数组进行更新。当我滚动 Collection View 时,其顺序正在更改。任何帮助将不胜感激。

最佳答案

检查下面的代码。可能对你有帮助

for (UIImageView *imgView in cell.subviews) {
if ([imgView isKindOfClass:[UIImageView class]]) {
[imgView removeFromSuperview];
}
}

然后添加你的 View

UIImageView *segmentImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 5, cell.frame.size.width - 10, cell.frame.size.height - 10)];
segmentImageView.image = [segmentControlArray objectAtIndex:indexPath.row];
segmentImageView.contentMode = UIViewContentModeScaleAspectFit;
[cell addSubview:segmentImageView];

关于ios - 停止在 Collection View 中重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40407354/

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