1

I have a problem on a tableview with section by date. I took the Apple example : DateSectionTitles

I don't care about year. I ust need month and day. So I adapt my code like that :

In my CoreData class :

- (NSString *)sectionIdentifier {
[self willAccessValueForKey:@"sectionIdentifier"];
NSString *tmp = [self primitiveSectionIdentifier];
[self didAccessValueForKey:@"sectionIdentifier"];
NSLog(@"!Temp");
if (!tmp) {
    NSCalendar *calendar = [NSCalendar currentCalendar];

    NSDateComponents *components = [calendar components:(NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:[self timeStamp]];
    tmp = [NSString stringWithFormat:@"%d", ([components month]*100) + [components day]];
    [self setPrimitiveSectionIdentifier:tmp];
}
return tmp;}

And in my titleForHeaderInSection method in my main controller :

NSInteger month = numericSection / 100;
NSInteger day = numericSection - (month * 100);

NSString *titleString = [NSString stringWithFormat:@"%d %d",day, month];

return titleString;

But when I run my app I have this message :

CoreData: error: (NSFetchedResultsController) A section returned nil value for section name key path 'sectionIdentifier'. Objects will be placed in unnamed section

Do you know why ? Thanks for your help !

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Pierre
  • 10,593
  • 5
  • 50
  • 80

2 Answers2

3

One common mistake usually coding transient property for nsmanagedobject, is people forget to also "enable" transient property in the data model file (xcdatamodeld).

netliner
  • 159
  • 1
  • 4
0

Logically, that would happen if at this line of your code

NSDateComponents *components = [calendar components:
   (NSMonthCalendarUnit | NSDayCalendarUnit) 
   fromDate:[self timeStamp]];

[self timeStamp] returns an invalid NSDate. Check with NSLog statements if that is the case.

Mundi
  • 79,884
  • 17
  • 117
  • 140