how it works UILocalizedIndexedCollation?
I read the sample code from the documentation, initialized RootViewController, we send it some data ( rootViewController.timeZonesArray = timeZones;), but at this point it is collationalready used in the view controller:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [[collation sectionTitles] count];
}
Basically, this is where the magic seems to be happening, so what does it contain [collation sectionTitles]? something should be automatic, but I don’t see how it all works?
- (void)configureSections {
self.collation = [UILocalizedIndexedCollation currentCollation];
NSInteger index, sectionTitlesCount = [[collation sectionTitles] count];
NSMutableArray *newSectionsArray = [[NSMutableArray alloc] initWithCapacity:sectionTitlesCount];
for (index = 0; index < sectionTitlesCount; index++) {
NSMutableArray *array = [[NSMutableArray alloc] init];
[newSectionsArray addObject:array];
[array release];
}
for (TimeZoneWrapper *timeZone in timeZonesArray) {
NSInteger sectionNumber = [collation sectionForObject:timeZone collationStringSelector:@selector(localeName)];
NSMutableArray *sectionTimeZones = [newSectionsArray objectAtIndex:sectionNumber];
[sectionTimeZones addObject:timeZone];
}
for (index = 0; index < sectionTitlesCount; index++) {
NSMutableArray *timeZonesArrayForSection = [newSectionsArray objectAtIndex:index];
NSArray *sortedTimeZonesArrayForSection = [collation sortedArrayFromArray:timeZonesArrayForSection collationStringSelector:@selector(localeName)];
[newSectionsArray replaceObjectAtIndex:index withObject:sortedTimeZonesArrayForSection];
}
self.sectionsArray = newSectionsArray;
[newSectionsArray release];
}
thanks for the help
source
share