将mediaItemCollection数据放在UITableView中 [英] Place mediaItemCollection data in UITableView

查看:91
本文介绍了将mediaItemCollection数据放在UITableView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助,将mediaItemCollection数据放入UITableView.

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

代码:

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

mediaItemCollection是我需要放入UITableView的东西.

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

推荐答案

我找到了代码:)

通过声明MPMediaItemCollection并设置其内容,我可以在更新UITableView的数据时读取mediaItemCollection.

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

这篇关于将mediaItemCollection数据放在UITableView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆