我有一個表使用NSFetchedResultsController。這讓我與存在NSFetchedResultsController與索引UITableViewController和UILocalizedIndexedCollation
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[_fetchedResultsController sections] count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [[[_fetchedResultsController sections] objectAtIndex:section] name];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger numberOfRows = 0;
NSArray *sections = _fetchedResultsController.sections;
if(sections.count > 0)
{
id <NSFetchedResultsSectionInfo> sectionInfo = [sections objectAtIndex:section];
numberOfRows = [sectionInfo numberOfObjects];
}
return numberOfRows;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return [_fetchedResultsController sectionIndexTitles];
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
return [_fetchedResultsController sectionForSectionIndexTitle:title atIndex:index];
}
頭的索引,但我想用UILocalizedIndexCollation以獲得完整的字母表。
如何將這些方法連接到NSFetchedResultsController?
我想我需要從目前的整理
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
}
獲得指數冠軍,但我失去了對如何寫這個方法
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
//How do I translate index here to be the index of the _fetchedResultsController?
return [_fetchedResultsController sectionForSectionIndexTitle:title atIndex:index];
}
檢查我的擴展答案:http://stackoverflow.com/a/15587961/1791090 – dimanitm 2013-03-23 14:43:43