UIProgressView在自定义UITableViewCell中更新自身

时间:2017-05-18 11:27:52

标签: ios objective-c uitableview tableviewcell uiprogressview

我有一个用几个自定义UITableViewCell填充的UITableView。在其中一个中,我有一个代表一定百分比数据的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设置放在另一个单元的委托方法中?

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

根据UIProgressView documentation

  

当前进度由0.0到1.0之间的浮点值表示,其中1.0表示任务完成。默认值为0.0。小于0.0且大于1.0的值固定在这些限制之上。

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