【问题标题】:Add UIProgressBar to UITableViewCell将 UIProgressBar 添加到 UITableViewCell
【发布时间】:2015-06-30 15:25:25
【问题描述】:

我需要在流式传输音频剪辑时在UITableviewCell 中显示UIProgressBar

我尝试运行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;

输出应该与此类似

【问题讨论】:

  • 尝试在 UIViewController 中将 UITableViewCell 作为 iVar。我认为您的进度正在被重置,或者至少该值没有被保留。

标签: ios objective-c uitableview uiprogressview uiprogressbar


【解决方案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]; 

【讨论】:

  • 那么,以上两种方法有什么区别呢?这两种变体都调用 UITableViewDataSource 方法 cellForRowAtIndexPath。这取决于您如何在该方法中创建单元格。
【解决方案2】:

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

【讨论】:

  • 确实删除了 [self.tblView reloadData]。但什么也没发生
猜你喜欢
  • 1970-01-01
  • 2011-12-01
  • 2012-03-30
  • 1970-01-01
  • 1970-01-01
  • 2016-01-29
  • 1970-01-01
  • 2010-10-18
  • 1970-01-01
相关资源
最近更新 更多