【问题标题】:simple mistake on the function功能上的简单错误
【发布时间】:2014-01-02 07:35:26
【问题描述】:

我想在我的 tableview 上显示一个索引栏,其中包含按字母顺序排序的所有歌曲和 # 中的那些外语歌曲,就像 iOS 中的 iPod 音乐一样。
但是我得到了一个错误

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LibraryViewController partitionSongObjects:collationStringSel:]: unrecognized selector sent to instance 0x1454be90'

非常感谢任何 cmets。

//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;
}

【问题讨论】:

  • 你的方法被称为partitionSongObjects:collationStringSelector: 而不是partitionSongObjects:collationStringSel:

标签: ios objective-c uitableview indexing uilocalizedcollation


【解决方案1】:

您调用了一个简单的错误输入方法名称:[self partitionSongObjects:songNameArray collationStringSel:@selector(songName)],而您可能应该: [self partitionSongObjects:songNameArray collationStringSelector:@selector(songName)]

【讨论】:

    猜你喜欢
    • 2018-11-16
    • 2012-11-08
    • 1970-01-01
    • 2013-10-17
    • 1970-01-01
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多