代碼工作並用表格填充表格,但它有一個缺陷:它不會在標題中跳出標點和'The'前綴,只是比如原生音樂應用程序的功能。整理MPMediaQuery時在歌名中跳出標點符號和'The'前綴
真的很感謝一些關於如何去做這件事的指導。
- (void)viewDidLoad
{
[super viewDidLoad];
MPMediaQuery *songQuery = [MPMediaQuery songsQuery];
self.songsArray = [songQuery items];
self.sectionedSongsArray = [self partitionObjects:self.songsArray collationStringSelector:@selector(title)];
}
- (NSArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector
{
UILocalizedIndexedCollation *collation = [UILocalizedIndexedCollation currentCollation];
NSInteger sectionCount = [[collation sectionTitles] count];
NSMutableArray *unsortedSections = [NSMutableArray arrayWithCapacity:sectionCount];
for(int i = 0; i < sectionCount; i++)
{
[unsortedSections addObject:[NSMutableArray array]];
}
for (id object in array)
{
NSInteger index = [collation sectionForObject:object collationStringSelector:selector];
[[unsortedSections objectAtIndex:index] addObject:object];
}
NSMutableArray *sections = [NSMutableArray arrayWithCapacity:sectionCount];
for (NSMutableArray *section in unsortedSections)
{
[sections addObject:[collation sortedArrayFromArray:section collationStringSelector:selector]];
}
return sections;
}
你能分享一下你是如何實現這個的嗎?我被困在同一件事上,我要瘋了!它是否適用於其他MPMediaItems/MPMediaCollections的列表?謝謝 – topLayoutGuide 2013-02-07 13:30:11
我用分區對象方法編寫了我的整個媒體庫。這在某種程度上「很快」,但這對於MPMediaQuerySection來說更快。一些幫助將不勝感激! – topLayoutGuide 2013-02-08 12:35:06