将UIProgressBar添加到UITableViewCell

sma*_*nja 11 objective-c uitableview uiprogressview uiprogressbar ios

我需要UIProgressBarUITableviewCell播放音频剪辑时显示输入.

我尝试运行a NSTimer然后尝试更新进度视图,但它不起作用.这是我的代码.请让我知道这种方法有什么问题.

运行计时器

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

更新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];
}
Run Code Online (Sandbox Code Playgroud)

的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;
Run Code Online (Sandbox Code Playgroud)

输出应该与此类似

在此输入图像描述

sma*_*nja 1

几乎两天后终于发现了问题:( :( 错误在这一行

错误的

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

已更正

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