混合言語データで FRC を使用しようとしていますが、セクション インデックスが必要です。
ドキュメントから、FRCをオーバーライドできるはずのようです
- (NSString *)sectionIndexTitleForSectionName:(NSString *)sectionName
- (NSArray *)sectionIndexTitles
次に、UILocalizedIndexedCollation を使用してローカライズされたインデックスとセクションを作成します。しかし悲しいことに、これは機能せず、使用することを意図したものではありません:(
UILocalizedIndexedCollation で FRC を使用できた人はいますか、それとも UITableView + UILocalizedIndexedCollation の例 (これを機能させた場所にコードが含まれています) に記載されている手動の並べ替え方法を使用することを余儀なくされていますか?
次のプロパティの使用
@property (nonatomic, assign) UILocalizedIndexedCollation *collation;
@property (nonatomic, assign) NSMutableArray *collatedSections;
そしてコード:
- (UILocalizedIndexedCollation *)collation
{
if(collation == nil)
{
collation = [UILocalizedIndexedCollation currentCollation];
}
return collation;
}
- (NSArray *)collatedSections
{
if(_collatedSections == nil)
{
int sectionTitlesCount = [[self.collation sectionTitles] count];
NSMutableArray *newSectionsArray = [[NSMutableArray alloc] initWithCapacity:sectionTitlesCount];
collatedSections = newSectionsArray;
NSMutableArray *sectionsCArray[sectionTitlesCount];
// Set up the sections array: elements are mutable arrays that will contain the time zones for that section.
for(int index = 0; index < sectionTitlesCount; index++)
{
NSMutableArray *array = [[NSMutableArray alloc] init];
[newSectionsArray addObject:array];
sectionsCArray[index] = array;
[array release];
}
for(NSManagedObject *call in self.fetchedResultsController.fetchedObjects)
{
int section = [collation sectionForObject:call collationStringSelector:NSSelectorFromString(name)];
[sectionsCArray[section] addObject:call];
}
NSArray *sortDescriptors = self.fetchedResultsController.fetchRequest.sortDescriptors;
for(int index = 0; index < sectionTitlesCount; index++)
{
[newSectionsArray replaceObjectAtIndex:index withObject:[sectionsCArray[index] sortedArrayUsingDescriptors:sortDescriptors]];
}
}
return [[collatedSections retain] autorelease];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// The number of sections is the same as the number of titles in the collation.
return [[self.collation sectionTitles] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// The number of time zones in the section is the count of the array associated with the section in the sections array.
return [[self.collatedSections objectAtIndex:section] count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if([[self.collatedSections objectAtIndex:section] count])
return [[self.collation sectionTitles] objectAtIndex:section];
return nil;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return [self.collation sectionIndexTitles];
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
return [self.collation sectionForSectionIndexTitleAtIndex:index];
}
FRCDelegate プロトコルを使用して、更新の通知を受け取ることができるようにしたいと考えています。この 2 つのオブジェクトをうまく連携させる良い方法はないようです。