2010-06-01 36 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