我有一个包含UIProgressView的TableViewCell,我将进度值设置为Controller中的UIProgressView然后等于它们(即self.progressBar = cell.progressBar),但在iOS8和9中,在UI中进度条卡住了在0中,但在iOS7中它的作品。希望得到帮助。谢谢〜下面是我的代码:
@property (strong, nonatomic) IBOutlet UIProgressView *progressBar;
- (void)viewDidLoad{
[super viewDidLoad];
self.timer = [NSTimer scheduledTimerWithTimeInterval: 0.1f target:self selector: @selector(handleProgressBar) userInfo: nil repeats: YES];
[self.tableView reloadData];
}
- (void) handleProgressBar{
if(self.usedTime >= 300.0)
{
[self.timer invalidate];
self.timer=nil;
}
else
{
self.usedTime += 1;
CGFloat progress = self.usedTime*(0.0033333333);
[self performSelectorOnMainThread:@selector(updateProgress:) withObject:[NSNumber numberWithFloat:progress] waitUntilDone:NO];
if(self.usedTime>200){
[self.progressBar setProgressTintColor:[UIColor redColor]];}
}
}
- (void)updateProgress:(NSNumber *)progress {
float fprogress = [progress floatValue];
[self.progressBar setProgress:fprogress animated:YES];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.section) {
case 0:
return [self configQuestionCellWithQIndex:self.pageIndex+1];
break;
default:
return nil;
break;
}
}
- (QuestionTableViewCell*) configQuestionCellWithQIndex:(NSInteger)qIndex{
QuestionTableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"QuestionCell"];
[cell configCellWithQuestion:self.currentQuestion withQIndex:qIndex];
self.progressBar = cell.progressBar;
return cell;
}
答案 0 :(得分:0)
只是一个简单的想法 - 你有没有试过交换线:
self.progressBar = cell.progressBar;
使用:
cell.progressBar = self.progressBar;
如果修复它,那么我无法看到它如何在iOS7上运行,但不能在iOS8或iOS9上运行。
另一个选择是在ViewController和UITableViewCell中使用UIProgressView的不同实例 - 并且可能使用updateProgress:
方法的通知更新单元格中的UIProgressView?
答案 1 :(得分:0)
在$users[1]='us1';$users[2]='admin';
main thread
尝试在主线程上执行UI更新。
更新:
你可以做这样的事情来更新单元格中的进度条,
dispatch_async(dispatch_get_main_queue(), ^{
cell.progressBar = self.progressBar;
//or
self.progressBar = cell.progressBar;
});
并称之为,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//... your code...
cell.progressView.progress = progressValues[indexPath.row];
// ...
return cell;
}
有关详细信息,请参阅this link。
希望这会有所帮助:)