我想在我的 tableview 上显示一个索引栏,其中包含按字母顺序排序的所有歌曲以及 # 中的那些外语歌曲,就像 iOS 中的 iPod 音乐一样。
但是我得到了一个错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LibraryViewController partitionSongObjects:collationStringSel:]: unrecognized selector sent to instance 0x1454be90'
任何意见都非常感谢谢谢。
//viewDidLoad
[[MediaService sharedService]getAllSongsItemInSongs:^(NSArray *data) {
self.songArray = [[NSMutableArray alloc]initWithArray:data];
}];
NSMutableArray *songNameArray = [NSMutableArray array];
for (Song *songNameItem in self.songArray)
{
[songNameArray addObject:songNameItem.songName];
}
self.sectionArray = [self partitionSongObjects:songNameArray collationStringSel:@selector(songName)];
[self.songLibraryTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
- (NSMutableArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector
{
self.collation = [UILocalizedIndexedCollation currentCollation];
NSInteger sectionCount = [[self.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 = [self.collation sectionForObject:object collationStringSelector:selector];
[[unsortedSections objectAtIndex:index] addObject:object];
}
NSMutableArray *sections = [NSMutableArray arrayWithCapacity:sectionCount];
for (NSMutableArray *section in unsortedSections)
[sections addObject:[self.collation sortedArrayFromArray:section collationStringSelector:selector]];
return sections;
}