我有一个应用程序可以处理核心数据。数据有一个带有日期的字段,我想在单独的部分中显示一个月的每个条目。
我该如何获取数据?我使用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]; }
获取我的实际数据对象。
谢谢
在实例化FetchedResultsController时,请确保设置了sectionNameKeyPath。
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"dateKey" cacheName:@"Root"];