首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将UIProgressBar添加到UITableViewCell

将UIProgressBar添加到UITableViewCell
EN

Stack Overflow用户
提问于 2015-06-30 15:25:25
回答 2查看 371关注 0票数 11

在播放音频剪辑时,我需要在UIProgressBar中显示UITableviewCell

我试着运行一个NSTimer,然后尝试更新进度视图,但它不起作用。这是我的密码。请告诉我这种方法有什么问题。

运行计时器

代码语言:javascript
复制
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.25
                                          target:self
                                        selector:@selector(updatePlayProgress)
                                        userInfo:nil
                                         repeats:YES];

在TableviewCell中更新UIProgressView

代码语言:javascript
复制
- (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

代码语言:javascript
复制
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;

输出应该类似于

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-02 17:46:50

在将近两天后,终于发现了这个问题:( :(错误在这一行中)

错误

代码语言:javascript
复制
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:playingIndex inSection:0];
FeedCell *cell = (FeedCell*)[self tableView:self.tblView cellForRowAtIndexPath:indexPath];

校正

代码语言:javascript
复制
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:playingIndex inSection:0];
FeedCell *cell = (FeedCell*)[self.tblView cellForRowAtIndexPath:indexPath]; 
票数 1
EN

Stack Overflow用户

发布于 2015-06-30 16:24:25

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31142393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档