如何在表视图中允许重复条目

时间:2013-05-24 15:57:36

标签: objective-c uitableview 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;
}

0 个答案:

没有答案