2009-12-31 63 views
0

我想在這裏使用的例子添加一個AZ指數爲填充核心數據表核心數據:http://blog.sallarp.com/iphone-core-data-uitableview-drill-down/與AZ部分

但是,我不能工作了,我可以在我的設置屬性sectionNameKeyPath核心數據幫助頭文件:

是否需要製作NSFetchedResultsController,就像它們在CoreDataBooks中一樣?或者我可以在這裏的某處添加它?!對不起,對於無知,任何想法/幫助將不勝感激(這是第3天,我的頭髮把它撕掉)。

+(NSMutableArray *) searchObjectsInContext: (NSString*) entityName : (NSPredicate *) predicate : (NSString*) sortKey : (BOOL) sortAscending : (NSManagedObjectContext *) managedObjectContext 
{ 

    NSFetchRequest *request = [[NSFetchRequest alloc] init]; 
    NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:managedObjectContext]; 
    [request setEntity:entity]; 

    // If a predicate was passed, pass it to the query 
    if(predicate != nil) 
    { 
     [request setPredicate:predicate]; 
    } 

    // If a sort key was passed, use it for sorting. 
    if(sortKey != nil) 
    { 
     NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortKey ascending:sortAscending]; 
     NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; 
     [request setSortDescriptors:sortDescriptors]; 

     [sortDescriptors release]; 
     [sortDescriptor release]; 
    } 

    NSError *error; 

    NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy]; 

    [request release]; 

    return mutableFetchResults; 
} 

回答

3

您需要實現合適的表視圖數據源的方法(sectionIndexTitlesForTableView:和的tableView:sectionForSectionIndexTitle:atIndex :)。

我會推薦使用NSFetchedResultsController來做到這一點。查看this answerCore Data backed UITableView with indexing的示例代碼。