Подтвердить что ты не робот

Добавить UIProgressBar в UITableViewCell

У меня есть требование отображать UIProgressBar в UITableviewCell при потоковой передаче аудиоклипа.

Я попробовал запустить NSTimer, а затем попытался обновить представление прогресса, но он не работает. Это мой код. Пожалуйста, дайте мне знать, что случилось с этим подходом.

Запустить таймер

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

Обновить UIProgressView в TableviewCell

- (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

4b9b3361

Ответ 1

В конце концов нашла проблему спустя почти 2 дня:(:( Ошибка в этой строке

Wrong

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]; 

Ответ 2

Когда вы вызываете [self.tblView reloadData], вы устанавливаете индикатор выполнения на 0.0 в следующей строке fCell.progressPlay.progress = 0.0. Удалите вызов reloadData.