0

我希望能够将带有重复歌曲标题的播放列表加载到表格视图中。However when the playlist is selected the table view automatically removes the duplicates? 如何防止这种情况并允许重复项显示在表格视图中?

这是我正在使用的代码:

- (void) updatePlayerQueueWithMediaCollection: (MPMediaItemCollection *) mediaItemCollection
{
    // Configure the music player, but only if the user chose at least one song to play
    if (mediaItemCollection)
    {

    if (_userMediaItemCollection == nil)
    {
        self.userMediaItemCollection = mediaItemCollection;
        [[GVMusicPlayerController sharedInstance ] setQueueWithItemCollection: _userMediaItemCollection];

        if (array == nil)
        {
            [self savePlaylist:[MPMediaItemCollection collectionWithItems: self.userMediaItemCollection.items]];
        }
        else
        {
        [array addObjectsFromArray:self.userMediaItemCollection.items];
        [self savePlaylist:[MPMediaItemCollection collectionWithItems: array]];
        }
    }
    else
    {
        NSMutableArray *currentSongsList= [[_userMediaItemCollection items] mutableCopy];
        NSArray *nowSelectedSongsList = [mediaItemCollection items];
        [currentSongsList addObjectsFromArray:nowSelectedSongsList];
        self.userMediaItemCollection = [MPMediaItemCollection collectionWithItems:(NSArray *) currentSongsList];

        // Apply the new media item collection as a playback queue for the music player.
        [[GVMusicPlayerController sharedInstance ] setQueueWithItemCollection: _userMediaItemCollection];
        [[GVMusicPlayerController sharedInstance] pause];

        //save playlist
        [array addObjectsFromArray:_userMediaItemCollection.items];
        [self savePlaylist:[MPMediaItemCollection collectionWithItems: array]];
    }
  }
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //this method is called to fill out table with data
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:@"Cell"];
    }

    // populate the cell from array
    anItem = nil;
    anItem = [array objectAtIndex:indexPath.row];

        // Configure the cell
    cell.textLabel.text = [anItem valueForProperty:MPMediaItemPropertyTitle];
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

    return cell;
}
4

0 回答 0