Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios ProgressView未显示在所有UICollectionViewCells中_Ios_Progress Bar_Uicollectionviewcell - Fatal编程技术网

Ios ProgressView未显示在所有UICollectionViewCells中

Ios ProgressView未显示在所有UICollectionViewCells中,ios,progress-bar,uicollectionviewcell,Ios,Progress Bar,Uicollectionviewcell,我的问题是ProgressView只显示在前两个单元格中。我的代码有什么问题 注意:我的收藏视图水平滚动,每个单元格覆盖整个屏幕。我想这可能有点关系,因为我尝试在同一个视图中显示所有单元格,它们工作正常。所有视图都显示 编辑的代码: -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static

我的问题是ProgressView只显示在前两个单元格中。我的代码有什么问题

注意:我的收藏视图水平滚动,每个单元格覆盖整个屏幕。我想这可能有点关系,因为我尝试在同一个视图中显示所有单元格,它们工作正常。所有视图都显示

编辑的代码:

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

static NSString *cellIdentifier = @"Cell";
VestimentaDetailCell *cell = (VestimentaDetailCell *) [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

cell.progressView.hidden = NO;
[cell.progressView setProgress:0.02];

PFFile *storeLooks = [self.vestimenta objectForKey:[NSString stringWithFormat:@"image_%ld", (long)indexPath.item]];

NSMutableString *precio = [NSMutableString string];
for (NSString* precios in [self.vestimenta objectForKey:[NSString stringWithFormat:@"precios_%ld", (long)indexPath.item]]) {
[precio appendFormat:@"%@\n", precios];}

[storeLooks getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error && data.length > 0) {

cell.imageFile.image = [UIImage imageWithData:data];

} else {

    cell.progressView.hidden = YES;

        }

} progressBlock:^(int percentDone) {
    float percent = percentDone * 0.02;
    [cell.progressView setProgress:percent];
    if (percentDone == 100){
        cell.progressView.hidden = YES;
    } else {
    cell.progressView.hidden = NO;
 }

}];

return cell;
}

我认为这与屏幕上的细胞被重复使用有关。由于要从单元格[cell.progressView removeFromSuperview]中删除progressView,因此一旦它退出队列,它仍然会丢失。您可以尝试重写RetentimentAdealCell类中的prepareForReuse方法以将其添加回原来的状态,这样所有出列的单元格都会恢复到原来的状态。

您不必从单元格中删除进度视图,只需
设置Hidden:YES

这样,当重复使用单元格时,将出现进度视图,然后当您想开始在该单元格中加载内容时,可以
setHidden:NO

重复使用时,还要注意单元格内的进度块。请记住,如果单元格被重用,请取消加载操作;如果单元格未被其他数据项重用,请确保进度块仅继续更新其单元格


例如,我将进度设置为
0。
在此处显示进度视图,如下所示:

VestimentaDetailCell *cell = (VestimentaDetailCell *) [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

cell.progressView.hidden = NO;
[cell.progressView setProgress:0.];
由于您在数据加载完成时隐藏了progressView,因此我将在progressBlock中删除以下代码:

  if (percentDone == 100){
    cell.progressView.hidden = YES;
  } else {
    cell.progressView.hidden = NO;
  }

你能帮我输入以下代码吗?我已经更新了我的代码,但它似乎有同样的问题。只有前两个单元格使用进度视图,其余单元格为空。我还有一个“喜欢”按钮,注意到当我喜欢一张图片时。。下一个图像也会被喜欢并跳过2个图像。与progressView相同。注意:只有当我水平滚动collectionView时才会发生这种情况。不,它会完全删除progressView。虽然我已经在代码的第一部分添加了0.02的进度,但它似乎正在工作。我还在不同的环境下测试它。