sectionIndexTitlesForTableView键是关闭的? [英] sectionIndexTitlesForTableView keys are off?

查看:294
本文介绍了sectionIndexTitlesForTableView键是关闭的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的tableview实现了一个Section Index。它返回存储在coredata中的正确字母( A B C D F G H I K M N O P Q R S T U V W )。然而,索引已关闭。

I have implemented a Section Index for my tableview. It returns the correct letters for what is stored in coredata (A B C D F G H I K M N O P Q R S T U V W). However the indexes are off.

如果我点击字母 M ,我需要写信给我,等等。我试图排序的索引的名称是 name

If I click on the letter M it takes me to letter I, etc.. The name of the index I am attempting to sort on is name

我有什么办法要做的修复索引?

What is there for me to do to fix the index?

我还在实现 numberOfSectionsInTableView numberOfRowsInSection titeForHeaderInSection 。节标题正确显示。

I am also implementing numberOfSectionsInTableView,numberOfRowsInSection, and titeForHeaderInSection. The section headers are displayed correctly.

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {

    NSArray * sectionTitlesArray = [fetchedResultsController sectionIndexTitles];
    NSMutableArray *newTitles = [[NSMutableArray alloc] init];
    for (NSString *state in sectionTitlesArray) {
        [newTitles addObject:[NSString stringWithFormat:@"%@", state]];
    }
    return [newTitles autorelease];
}

包括FRC以防万一相关:

Including the FRC just in case it is relevant:

- (NSFetchedResultsController *)fetchedResultsController {
    if (fetchedResultsController == nil) {
        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
        NSEntityDescription *entity = [NSEntityDescription entityForName:@"WidgetCoItems" inManagedObjectContext:managedObjectContext];
        [fetchRequest setEntity:entity];

        NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"state" ascending:YES];

        NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];

        NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1,sortDescriptor2, nil];

        [fetchRequest setSortDescriptors:sortDescriptors];

        NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"state" cacheName:nil];
        aFetchedResultsController.delegate = self;
        self.fetchedResultsController = aFetchedResultsController;

        [aFetchedResultsController release];
        [fetchRequest release];
        [sortDescriptor1 release];
        [sortDescriptor2 release];
        [sortDescriptors release];
    }   
    return fetchedResultsController;
}  


推荐答案

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView 
{
        NSMutableArray *indices = [NSMutableArray array];

        id <NSFetchedResultsSectionInfo> sectionInfo;

        for( sectionInfo in [fetchedResultsController sections] )
        {
            [indices addObject:[sectionInfo name]];
        }
        return indices;
}

- (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section
{
    return [[[fetchedResultsController sections] objectAtIndex:section] name];
}

尝试以这种方式实施。

这篇关于sectionIndexTitlesForTableView键是关闭的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆