2

I need some help placing the mediaItemCollection data in a UITableView.

Code:

// Responds to the user tapping Done after choosing music.
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {    
    [self dismissModalViewControllerAnimated: YES];

    [musicPlayer stop];
    [[MPMusicPlayerController iPodMusicPlayer] stop];
    [[MPMusicPlayerController iPodMusicPlayer] setQueueWithItemCollection:mediaItemCollection];
    [[MPMusicPlayerController iPodMusicPlayer] play];
}

The mediaItemCollection is what I need to place into my UITableView.

Rizier123
  • 58,877
  • 16
  • 101
  • 156
Aleksander Azizi
  • 9,829
  • 9
  • 59
  • 87

1 Answers1

0

I found the code :)

By declaring an MPMediaItemCollection and setting its content, I can read the mediaItemCollection when updating the UITableView's data.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"song_cell"];

    cell = [[UITableViewCell alloc]
            initWithStyle:UITableViewCellStyleSubtitle 
            reuseIdentifier:@"song_cell"];

    MPMediaItem *anItem = [[collection items] objectAtIndex:indexPath.row];

    cell.textLabel.text = [anItem valueForProperty:MPMediaItemPropertyTitle];
    cell.detailTextLabel.text = [anItem valueForProperty:MPMediaItemPropertyArtist];

    [tableView reloadData];
}
Aleksander Azizi
  • 9,829
  • 9
  • 59
  • 87