Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将UIProgressBar添加到UITableViewCell_Ios_Objective C_Uitableview_Uiprogressview_Uiprogressbar - Fatal编程技术网

Ios 将UIProgressBar添加到UITableViewCell

Ios 将UIProgressBar添加到UITableViewCell,ios,objective-c,uitableview,uiprogressview,uiprogressbar,Ios,Objective C,Uitableview,Uiprogressview,Uiprogressbar,我需要在播放音频剪辑时在UITableviewCell中显示UIProgressBar 我尝试运行一个NSTimer,然后尝试更新进度视图,但它不起作用。这是我的密码。请让我知道这种方法有什么问题 运行计时器 self.timer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self

我需要在播放音频剪辑时在
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;
输出应该与此类似


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

的调用在将近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]; 

确实删除了[self.tblView reloadData]。但是没有发生任何事情。尝试将UITableViewCell作为UIViewController中的iVar。我认为您的进度正在重置,或者至少该值没有持久化。那么,上述两种方法之间的区别是什么?这两种变体都调用UITableViewDataSource方法CellForRowatineXpath。这取决于您在UIViewController中创建单元格的方式在方法上。