2012-12-13 35 views
0

我有一個iOS項目,我嘗試使用CoreData。如何通過Classname獲取iOS CoreData

在我的模型中,我有兩個類ChildAChildB誰從ParentClass繼承。

在我UITableViewController,我可以輕鬆地獲得所有對象:

NSEntityDescription *entity = [NSEntityDescription entityForName:@"ParentClass" inManagedObjectContext:self.managedObjectContext];

我想要現在實現由Classname是分組結果。但我不知道如何實現,在我NSFetchedResultsController爲帕拉姆sectionNameKeyPath

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"?????" cacheName:@"Master"];

我想使用的結果我UITableView應該是這個樣子

ChildA 
    Obj1 
    Obj2 
    Obj3 
    ... 
ChildB 
    Obj4 
    Obj5 
    Obj6 
    ... 

在此先感謝

回答

0

我發現了一個可能的方法來實現...

我聲明2 NSFetchedResultsController在我UITableViewController

@interface MMPOITableViewController : UITableViewController <NSFetchedResultsControllerDelegate> 
@property (strong, nonatomic) NSFetchedResultsController *childAFetchedResultsController; 
@property (strong, nonatomic) NSFetchedResultsController *childBFetchedResultsController; 
@end 

第一個是負責管理ChildA類的對象,第二個是負責管理ChildB類的對象。

然後我設法使用childAFetchedResultsControllerchildBFetchedResultsController取決於當前部分。

希望它能幫助別人;)

相關問題