UIProgressView 在自定义 UITableViewCell 中自行更新

UIProgressView update itself in custom UITableViewCell

我有一个 UITableView,其中填充了多个自定义 UITableViewCell。在其中一个中,我有一个 UIProgressView,它将代表一定百分比的数据。 但是,当我设置进度(假设为 50%)时,进度条出现在 50% 并自行更新,直到达到 100%...

这是我用来更新数据的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];


    if ([appliedTheme hasPrefix:@"DarkMode"]) {

        self.tableView.backgroundColor = [UIColor colorWithRed:0.20 green:0.20 blue:0.20 alpha:1.0];
        cell.backgroundColor = [UIColor colorWithRed:0.20 green:0.20 blue:0.20 alpha:1.0];
        cell.cardView.backgroundColor = [UIColor colorWithRed:0.30 green:0.30 blue:0.30 alpha:1.0];


        cell.storageIntroLabel.textColor = [UIColor whiteColor];
        cell.storageInfoTitle.textColor = [UIColor whiteColor];
        cell.deviceStorageTitle.textColor = [UIColor whiteColor];

    }else {

        self.tableView.backgroundColor = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1.0];
        cell.backgroundColor = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1.0];
        cell.cardView.backgroundColor = [UIColor whiteColor];


        cell.storageIntroLabel.textColor = [UIColor blackColor];
        cell.storageInfoTitle.textColor = [UIColor blackColor];
        cell.deviceStorageTitle.textColor = [UIColor blackColor];

    }


    if ([CellIdentifier isEqualToString:@"storageIntro"]) {

        cell.storageIntroImageView.image = [UIImage imageNamed:storageIntroIconToShow];
        cell.storageIntroLabel.adjustsFontSizeToFitWidth = YES;
        cell.storageIntroLabel.numberOfLines = 0;
        [cell.storageIntroLabel sizeToFit];
        cell.storageIntroLabel.text = NSLocalizedString(@"Here you can find informations about your storage and how FileStore is using your memory by types of files", nil);

    }else if ([CellIdentifier isEqualToString:@"storageInfo"]){

        cell.storageInfoTitle.text = NSLocalizedString(@"Storage Informations", nil);
        cell.deviceStorageTitle.adjustsFontSizeToFitWidth = YES;
        cell.deviceStorageTitle.text = NSLocalizedString(@"Device Storage", nil);
        cell.totalDeviceSpaceLabel.adjustsFontSizeToFitWidth = YES;
        cell.totalDeviceSpaceLabel.text = NSLocalizedString(@"Total space :", nil);
        cell.finalTotalDeviceSpaceLabel.text = totalDeviceSpaceString;
        cell.freeDeviceSpaceLabel.adjustsFontSizeToFitWidth = YES;
        cell.freeDeviceSpaceLabel.text = NSLocalizedString(@"Free space :", nil);
        cell.finalFreeDeviceSpaceLabel.text = totalDeviceFreeSpaceString;
        dispatch_async(dispatch_get_main_queue(), ^{

            [cell.deviceStorageProgressView setProgress:50 animated:YES];

        });

    }else {



    }


    return cell;

}

即使我不使用 bool animated:YES,进度条也会根据我设置的百分比自行更新... 这对我来说没有任何意义!我是否必须将 UIProgressView 设置放在另一个单元格的委托方法中?

在此先感谢您的帮助!

根据 UIProgressView documentation

The current progress is represented by a floating-point value between 0.0 and 1.0, inclusive, where 1.0 indicates the completion of the task. The default value is 0.0. Values less than 0.0 and greater than 1.0 are pinned to those limits.

您将其设置为 50,这将基本上转换为上限值 1。如果您需要,则需要将值设置为 0.5想要50%的进度。