我有一个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;
}
即使我不使用布尔animated:YES
,进度条也会随着时间的推移从我设置的百分比更新......这对我来说没有任何意义!我是否必须将 UIProgressView 设置放在另一个单元格的委托方法中?
提前感谢您的帮助!
根据UIProgressView文档
当前进度由介于 0.0 和 1.0(含 0.0 和 1.0(之间的浮点值表示,其中 1.0 表示任务完成。默认值为 0.0。小于 0.0 且大于 1.0 的值固定到这些限制。
您将其设置为 50,这基本上将转换为上限值 1。如果你想要 50% 的进度,你需要给出 0.5 的值。