2011-05-24 59 views
1

我目前正在查看Apple的AddMusic example,並在開始將其重寫入我的應用程序之前進行調試。MPMediaItemCollection刪除選定的隊列/集合?

我注意到它使得它自己的小歌曲被列出來。我想在表格視圖上使用滑動操作刪除用戶錯誤點擊的歌曲。

我已經實施了刷卡操作,但無法找到刪除特定行的方法?

任何想法都會很棒,下面是添加它的代碼。我試圖做倒轉,沒有運氣。如果不可能,我應該怎麼做?

乾杯

MainViewController *mainViewController = (MainViewController *) self.delegate; 
MPMediaItemCollection *currentQueue = mainViewController.userMediaItemCollection; 
MPMediaItem *anItem = (MPMediaItem *)[currentQueue.items objectAtIndex: row]; 

回答

4
一種

是MPMediaItemCollection不可變的,即,。你不能改變這些項目。您需要創建一個新的項目,其中所有項目的數量少於您要移除的項目數量。見下:

NSArray* items = [currentQueue items]; 
NSMutableArray* array = [NSMutableArray arrayWithCapacity:[items count]]; 
[array addObjectsFromArray:items]; 
[array removeObjectAtIndex:row]; 
MPMediaItemCollection* newCollection = [MPMediaItemCollection collectionWithItems:array]; 

小心不要創建一個空的集合。這是不允許的,並且MPMediaItemCollection會引發異常。