Простая ошибка в функции
Я хотел бы показать индексную полосу на моем табличном представлении со всеми моими песнями, отсортированными по алфавиту, и этими песнями на иностранном языке в # так же, как это делает музыка iPod в iOS.
Однако я получил ошибку
*** 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;
}
1 ответ
Решение
У вас есть простое имя метода опечатки, который вы вызываете: [self partitionSongObjects:songNameArray collationStringSel:@selector(songName)]
тогда как вы, вероятно, должны:[self partitionSongObjects:songNameArray collationStringSelector:@selector(songName)]