NSFetchedResultsController v.s. UILocalizedIndexedCollation

前端 未结 4 2112
慢半拍i
慢半拍i 2020-11-28 06:07

I am trying to use a FRC with mixed language data and want to have a section index.

It seems like from the documentation you should be able to override the FRC\'s

4条回答
  •  猫巷女王i
    2020-11-28 07:01

    Brent, my solution is based on FRC and I get sectioning from the fetch specifying a transient attribute on my model object that returns the section name for the object. I use UIlocalizedIndexedCollation only in the implementation of the attribute getter then I rely on the FRC implementation on the table view controller. Of course I use localizedCaseInsensitiveCompare as sorting selector on the fetch.

    - (NSString *)sectionInitial {
    
        NSInteger idx = [[UILocalizedIndexedCollation currentCollation] sectionForObject:self     collationStringSelector:@selector(localeName)];
        NSString *collRet = [[[UILocalizedIndexedCollation currentCollation] sectionTitles]     objectAtIndex:idx];
    
        return collRet;
    }
    

    The only drawback I have is that i can't have the # section at the end because I don't change the sorting from the DB. Everything else works well.

提交回复
热议问题