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
.
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];
}
来源:https://stackoverflow.com/questions/7128032/place-mediaitemcollection-data-in-uitableview