ios - 对于非英语歌曲,如何使用 # 显示看起来像 iPod 音乐的索引

标签 ios objective-c uitableview indexing

我想在我的 tableview 上显示一个索引栏,其中我的所有歌曲都按字母顺序排序,那些外语歌曲和数字在 # 中,就像 iOS 中的 iPod 音乐一样。 我读取了我所有歌曲数组对象的第一个字符,排除重复项并将其附加为索引。 我如何过滤外国/非字母和数字?

这就是它的样子,丑陋。

enter image description here

会显示 iPod 之类的东西。

enter image description here

   -(NSMutableArray *)updateSongSectionIndexWithArray:(NSArray*)songArray andSelector:(SEL)selector
{
    NSArray *indexedArray = [self partitionObjects:songArray collationStringSelector:selector];
   return [[NSMutableArray alloc]initWithArray:indexedArray];

}

-(NSArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector
{
    self.collation = [UILocalizedIndexedCollation currentCollation];
    NSInteger sectionCount = [[self.collation sectionTitles] count];//section count is take from sectionTitles and not sectionIndexTitles
    NSMutableArray *unsortedSections = [NSMutableArray arrayWithCapacity:sectionCount];
    //create an array to hold the data for each section
    for(int i = 0; i < sectionCount; i++)
    {
        [unsortedSections addObject:[NSMutableArray array]];
    }

    if ([self.catString isEqualToString:ARTISTS])
    {

        //put each object into a section
        for (id object in array)
        {
            if (!object)
            {
                continue;
            }

            NSInteger index = [self.collation sectionForObject:object collationStringSelector:selector];
            [[unsortedSections objectAtIndex:index] addObject:object];
        }
    }
    else
    {
        for (id object in array)
        {
            NSInteger index = [self.collation sectionForObject:object collationStringSelector:selector];
            [[unsortedSections objectAtIndex:index] addObject:object];
        }
    }

    NSMutableArray *sections = [NSMutableArray arrayWithCapacity:sectionCount];

    //sort each section
    for (NSMutableArray *section in unsortedSections)
    {
        [sections addObject:[self.collation sortedArrayFromArray:section collationStringSelector:selector]];
    }
    return sections;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] count];
}

最佳答案

我为联系人应用程序做了类似的解决方案。我首先自己定义字母表,然后您可以将适合的项目添加到每个部分(比较不区分大小写的字母,比较字符集的数字)。列表填满后,您可以删除(或隐藏)没有条目的部分。

关于ios - 对于非英语歌曲,如何使用 # 显示看起来像 iPod 音乐的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20896491/

相关文章:

ios - 将 ViewController 的 View 分配给自定义 View 类不会显示自定义 View 属性

ios - 添加自定义类查看后,UITableViewController 中的 UI 元素会消失吗?

ios - 使用社交框架在 Facebook 墙上分享位置

iphone - Objective-C 通讯录

iphone - 添加 iOS UITableView HeaderView(不是部分标题)

ios - 如何在我的表格 View 中进行单选和多选?

ios - 从 Web 下载图像或 mp3 文件到 iPhone 文档目录

ios - 不推荐使用 initForReadingWithData - initForReadingFromData 返回 nil

ios - 将新委托(delegate)添加到新 Controller 的问题

ios - 检测 tableView 中每个部分的最后一个单元格