我有一個問題,試圖顯示專輯&由某個藝術家在tableView中的各自的歌曲,按部分和行中的歌曲分開專輯標題。結構UITableView與自定義iPod庫
我使用這個代碼通過這個特定的藝術家,使一個NSArray所有專輯:
- (NSArray *)getAlbumsMatchingQuery:(NSString *)query
{
MPMediaPropertyPredicate *artistNamePredicate = [MPMediaPropertyPredicate predicateWithValue:query forProperty:MPMediaItemPropertyArtist];
MPMediaQuery *albumQuery = [[MPMediaQuery alloc] initWithFilterPredicates:[NSSet setWithObject:artistNamePredicate]];
[albumQuery setGroupingType:MPMediaGroupingAlbum];
/** each index of this array contains a media item collection.
each collection contains the media items from the iPod library by a particular artist.
the elements of the array are sorted by album name.
**/
NSArray *albums = [albumQuery collections];
NSMutableArray *arrayAlbums = [[NSMutableArray alloc] init];
for (MPMediaItemCollection *album in albums) {
MPMediaItem *representativeItem = [album representativeItem];
[arrayAlbums addObject:representativeItem];
}
return arrayAlbums;
}
現在我不知道如何顯示在我的tableview該結構通過專輯名稱和相應的分離歌曲。
任何建議是有效的,感謝
感謝您的回覆。我熟悉UITableViewDataSource,我的問題是這個結構,你談到了,一個鋸齒狀的二維數組。你介意給我一些簡單的代碼示例嗎?我真的被困在這... – 2014-09-03 20:26:46
你嘗試過嗎?(谷歌搜索?)(https://www.google.com/search?q=jagged+nsarray&gws_rd=ssl#q=jagged+array+objective+c)沒有什麼能夠阻止你將一些'NSArray'放到'NSArray'中。或者,如你所見,使用'NSMutableArray'。 – Gutblender 2014-09-04 13:35:01