2015-06-30 4 views
11

Ho un requisito per visualizzare uno UIProgressBar in UITableviewCell durante lo streaming di una clip audio.Aggiungi UIProgressBar a UITableViewCell

Ho provato a eseguire un NSTimer e quindi cercando di aggiornare la vista di avanzamento, ma non funziona. Questo è il mio codice Per favore fatemi sapere cosa c'è di sbagliato in questo approccio.

Eseguire il timer

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

Aggiornamento UIProgressView in 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; 

uscita dovrebbe essere qualcosa di simile a questo

enter image description here

+0

cercare di avere il vostro UITableViewCell come iVar nel tuo UIViewController. Penso che i tuoi progressi vengano ripristinati, o almeno t il valore non è persistente. – Jasper

risposta

1

alla fine ho trovato il problema dopo quasi due giorni :(:( errore è stato in questa linea

sbagliato

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

Corretto

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:playingIndex inSection:0]; 
FeedCell *cell = (FeedCell*)[self.tblView cellForRowAtIndexPath:indexPath]; 
+0

Quindi, qual è la differenza tra i due metodi sopra citati? Entrambe le varianti chiamano il metodo UITableViewDataSource cellForRowAtIndexPath. Dipende da come crei la cella all'interno di quel metodo. – Sandeep

0

Quando si chiama [self.tblView reloadData] si sta impostando la barra di avanzamento torna a 0.0 nella riga seguente fCell.progressPlay.progress = 0.0. Rimuovere la chiamata a reloadData.

+0

ha rimosso [self.tblView reloadData]. Ma non succede nulla – sajaz