将UIProgressBar添加到UITableViewCell

时间:2015-06-30 15:25:26

标签: ios objective-c uitableview uiprogressview uiprogressbar

我需要在播放音频片段时在UIProgressBar中显示UITableviewCell

我尝试运行NSTimer,然后尝试更新进度视图,但它无效。这是我的代码。请告诉我这种方法有什么不对。

运行计时器

self.timer = [NSTimer scheduledTimerWithTimeInterval:0.25
                                          target:self
                                        selector:@selector(updatePlayProgress)
                                        userInfo:nil
                                         repeats:YES];

更新TableviewCell中的UIProgressView

- (void)updatePlayProgress {
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    NSLog(@"Duration %f", appDelegate.moviePlayer.duration);
    NSLog(@"Current time %f", appDelegate.moviePlayer.currentPlaybackTime);

    float timeLeft = appDelegate.moviePlayer.currentPlaybackTime/appDelegate.moviePlayer.duration;

    // upate the UIProgress
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:playingIndex inSection:0];
    FeedCell *cell = (FeedCell*)[self tableView:self.tblView cellForRowAtIndexPath:indexPath];

    NSLog(@"Time left %f", timeLeft);

    cell.progressPlay.progress = 0.5;

    [cell.progressPlay setNeedsDisplay];
}

的cellForRowAtIndexPath

fCell.progressPlay.alpha = 0.5;
fCell.progressPlay.tintColor = navigationBarColor;
[fCell.progressPlay setTransform:CGAffineTransformMakeScale(fCell.frame.size.width, fCell.frame.size.height)];

[fCell.progressPlay setHidden:NO];

return fCell;

输出应与此类似

enter image description here

2 个答案:

答案 0 :(得分:1)

最近2天后发现了这个问题:( :( 错误就在这一行

<强>错误

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:playingIndex inSection:0];
FeedCell *cell = (FeedCell*)[self tableView:self.tblView cellForRowAtIndexPath:indexPath];

<强>校正的

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:playingIndex inSection:0];
FeedCell *cell = (FeedCell*)[self.tblView cellForRowAtIndexPath:indexPath]; 

答案 1 :(得分:0)

当您致电[self.tblView reloadData]时,您将进度条设置回以下0.0行中的fCell.progressPlay.progress = 0.0。移除对reloadData的电话。