2010-06-01 53 views
0

我有一個應用程序,與核心數據的工作。數據有一個日期字段,我想在一個單獨的部分顯示每個月的每個條目。CoreData和的UITableViewController問題

如何真正得到的數據?我使用NSFetchedResultsController來獲取數據,並使用此:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

    id <NSFetchedResultsSectionInfo> sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section]; 
    return [sectionInfo numberOfObjects]; 

} 

讓行和這樣的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
MyInfoObject *info = [_fetchedResultsController objectAtIndexPath:indexPath]; 
} 

讓我的實際數據對象。

感謝

+0

你可以添加你如何設置讀取的結果控制代碼的時候請確保您設置sectionNameKeyPath?這是部分設置的地方。 – 2010-06-01 20:43:39

回答

1

實例您fetchedResultsController

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"dateKey" cacheName:@"Root"]; 
+0

不幸的是,這給了我一個每一個日期的部分。我想要的只是這個月,我能做到的任何想法? – eemceebee 2010-06-02 16:11:10

+0

我想補充另一個屬性,可能稱它爲MONTH_YEAR ...這裏引用文檔... http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CoreData/Articles/cdAccessorMethods.html# // apple_ref/DOC/UID/TP40002154-SW13 – Travis 2010-06-02 21:36:15

+0

創建自定義管理對象類,這是我平時做...並創建一個自定義的getter和setter相似,其清單2和清單3 在做的方式在二傳我將改變日期對象轉換爲字符串「MMYYYY」,並在吸氣我會檢查的值,如果不存在的話,嘗試恢復您在使用吸氣日期相同的格式。 – Travis 2010-06-02 21:37:35