私はコアデータを初めて使用し、現在コアデータモデルを使用してアプリを構築しています。私が達成したいのは、各月のセクション ヘッダーで分割されたテーブルビューです。現時点では、各セルにすべてのデータを表示するアプリケーションが動作していますが、各月のセクション ヘッダーはありません。私が欲しいのは、"date" : "26/08/2012" のオブジェクトが、8 月というタイトルのセクションの下に表示されることです。
次のデータを持つjson Webサービスがあります。
"date": "26/08/2012",
"hour": "18u00",
"type": "JPL",
"home": "KRC Genk",
"away": "Zulte-Waregem",
"homeScore": "2",
"awayScore": "0"
その NSManagedObject サブクラスと、データベース内に値を格納するためのこのクラスのカテゴリを構築します。これはすべて機能します。これらの値をテーブルビューに入れるには、次の方法があります。
- (void)getKalender // attaches an NSFetchRequest to this UITableViewController
{
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Kalender"];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES]];
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.genkDatabase.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
}
そして、これは私の cellForRowAtIndexPath で行うことです
static NSString *simpleTableIdentifier = @"KalenderCell";
KalenderCell *cell = (KalenderCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if ((cell == nil) || (![cell isKindOfClass:KalenderCell.class]))
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"KalenderCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
// ask NSFetchedResultsController for the NSMO at the row in question
Kalender *kalender = [self.fetchedResultsController objectAtIndexPath:indexPath];
// Then configure the cell using it ...
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM"];
NSString *dateStr = [dateFormat stringFromDate:kalender.date];
cell.lblType.text = kalender.type;
cell.lblHome.text = kalender.home;
cell.lblHomeScore.text = kalender.homeScore;
cell.lblAwayScore.text = kalender.awayScore;
cell.lblAway.text = kalender.away;
cell.lblDate.text = dateStr;
cell.lblHour.text = kalender.hour;
return cell;
しかし、ここで私は立ち往生しています。NSFetchedResult コントローラーを使用してこれらのセクション ヘッダーを設定する方法を教えてください。
よろしくお願いします!