问题描述
|
我目前正在查看Apple的AddMusic示例,并在开始将其重写到应用程序之前对其进行处理。
我注意到它使自己的歌曲很少播放列表。我想在表格视图上使用滑动操作来删除误用的歌曲。
我已经实现了滑动操作,但是无法找到删除该特定行的方法吗?
任何想法都很棒,下面是添加代码的代码。我没有运气就试图做相反的事情。如果不可能,该怎么办?
干杯
MainViewController *mainViewController = (MainViewController *) self.delegate;
MPMediaItemCollection *currentQueue = mainViewController.userMediaItemCollection;
MPMediaItem *anItem = (MPMediaItem *)[currentQueue.items objectAtIndex: row];
解决方法
MPMediaItemCollection是不可变的,即。您无法更改项目。您需要创建一个新的项目,其中所有项目都少于要删除的项目。见下文:
NSArray* items = [currentQueue items];
NSMutableArray* array = [NSMutableArray arrayWithCapacity:[items count]];
[array addObjectsFromArray:items];
[array removeObjectAtIndex:row];
MPMediaItemCollection* newCollection = [MPMediaItemCollection collectionWithItems:array];
注意不要创建一个空集合。不允许,MPMediaItemCollection会引发异常。