Note that there are some explanatory texts on larger screens.

plurals
  1. PONSNotification observer in custom UITableViewCell?
    text
    copied!<p>I'm building an app with iPod-like controls (play, pause, etc). The app has tableView with track names in each cell. I have a <code>MainViewController</code> with a <code>UITableView</code> and a custom <code>UITableViewCell</code> class. The player controls exist in the <code>MainViewController</code>.</p> <p>I also have a play/pause button in each cell. I've successfully set up <code>NSNotifications</code> to post a notification when the play button is pressed in the cell, so the track info is sent to the observer and responder method in <code>MainViewController</code> and the player controls (driven by <code>MPMoviePlayerController</code>) is initiated.</p> <p>This works, but once the track is playing, I can't figure out how to make the play/pause button in the cell "mirror" the state of the play/pause button in my iPod controls. I don't think adding a <code>NSNotification observer</code> in every cell is the correct way of doing this. </p> <p>Additional info: The play/pause button image in the <code>MainViewController</code> player is determined by a method that fires every half second and checks the <code>playbackstate</code> of the <code>MPMoviePlayerController</code>. If playing, the player button set's the play image. If paused, it set's the pause image. I'm thinking the implementation to also set the tableCell play/pause button will go here. </p> <p><strong>Edit</strong> This method is called whenever the playback state changes (via NSNotification), within my UITableViewController. (<code>playButton</code> is the play/pause button in the player controls, not the play/pause in the table cell in which I'm trying to update according to playback state).</p> <pre><code>- (void) updateViewForPlayerState { // Change playButton image depending on playback state [playButton setImage:((moviePlayer.playbackState == MPMoviePlaybackStatePlaying) ? pauseBtnBG : playBtnBG) forState:UIControlStateNormal]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload