2011-11-07 7 views
1

私はテーブルビューのセクションインデックスを実装しました。 coredata(A B C D F G H I K M N O P Q R S T U V W)に格納されているものの正しい文字を返します。ただし、インデックスはオフです。私は手紙MをクリックするとsectionIndexTitlesForTableViewキーがオフですか?

それは私がなど、手紙に私を取る..私は上の整理しようとしていたインデックスの名前は、私は、インデックスを修正するために行うことのためにそこにある何name

のですか?

numberOfSectionsInTableView,numberOfRowsInSection、およびtiteForHeaderInSectionも実装しています。セクションヘッダーが正しく表示されます。 FRCを含む

- (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]; 
} 

念のためにそれが関連している:

- (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; 
} 
+0

あなたの 'fetchedResultsController'メソッドを呼び出すコードを表示できますか? I.選択された行/選択されたセクションメソッドがありますか? –

+0

私は間違っているかもしれませんが、私が理解しているように、定義された方法は暗黙的にFRCを読み込みます。私が見ることのできる「呼び出し」はありません。 (IE:viewDidLoad:loadTable :,など) – roberthuttinger

答えて

2
- (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]; 
} 

は、このように実装するようにしてください。

+0

ok私は違いを見て、私が逃したものを見なければならないでしょう... – roberthuttinger

+0

それはそれでした。私はいくつか微調整を追加する必要がありますが、私は今違いを見る...ありがとう! – roberthuttinger

0
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
if ([[<#Fetched results controller#> sections] count] > 0) { 
    id <NSFetchedResultsSectionInfo> sectionInfo = [[<#Fetched results controller#> sections] objectAtIndex:section]; 
    return [sectionInfo name]; 
} else 
    return nil; 
} 

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { 
return [<#Fetched results controller#> sectionIndexTitles]; 
} 

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { 
return [<#Fetched results controller#> sectionForSectionIndexTitle:title atIndex:index]; 
} 
関連する問題