Установка отдельного раздела для каждого месяца с fetchedresultcontroller

Я пытаюсь разделить мой просмотр таблицы на разделы для каждого месяца. Я начинаю работать сDateSectionTitles пример яблока. Прежде всего, я добавил в свою базовую базу данных атрибутsectionIdentifier», Затем в свой подкласс управляемого объекта я добавил этот метод.

- (NSString *)sectionIdentifier {

    // Create and cache the section identifier on demand.

    [self willAccessValueForKey:@"sectionIdentifier"];
    NSString *tmp = [self primitiveSectionIdentifier];
    [self didAccessValueForKey:@"sectionIdentifier"];

    if (!tmp) {
        /*
         Sections are organized by month and year. Create the section identifier as a string representing the number (year * 1000) + month; this way they will be correctly ordered chronologically regardless of the actual name of the month.
         */
        NSCalendar *calendar = [NSCalendar currentCalendar];

        NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit) fromDate:[self date]];
        tmp = [NSString stringWithFormat:@"%d", ([components year] * 1000) + [components month]];
          [self setPrimitiveSectionIdentifier:tmp];
    }
    NSLog(@"tmp: %@",tmp);
    return tmp;
}

Это то, что я делаю в своем заголовке ForHeaderSection

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
        id  theSection = [[self.fetchedResultsController sections] objectAtIndex:section];


    /*
     Section information derives from an event's sectionIdentifier, which is a string representing the number (year * 1000) + month.
     To display the section title, convert the year and month components to a string representation.
     */
    static NSArray *monthSymbols = nil;

    if (!monthSymbols) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setCalendar:[NSCalendar currentCalendar]];
        monthSymbols = [formatter monthSymbols];
    }

    NSInteger numericSection = [[theSection name] integerValue];

    NSInteger year = numericSection / 1000;
    NSInteger month = numericSection - (year * 1000);

    NSString *titleString = [NSString stringWithFormat:@"%@ %d", [monthSymbols objectAtIndex:month-1], year];
    NSLog(@"titelstring is: %@",titleString);
    return titleString;
}

Для моего количества строк в разделе я делаю это.

id  sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];

        NSInteger count = [sectionInfo numberOfObjects];
        return count;

И это для моего NumberOfSectionsInTableview

NSInteger count = [[self.fetchedResultsController sections] count];
        return count;

Кто-нибудь может помочь?

Заранее спасибо!

Что идет не так

Прежде всего все это неt печатает мой логин в NSLog (@ "tmp:% @ ", TMP); А также я получаю следующую ошибку:

CoreData: error: (NSFetchedResultsController) A section returned nil value for section name key path 'sectionIdentifier'. Objects will be placed in unnamed section
2012-10-10 10:41:17.475 RacingGenk[15785:c07] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (-1 (or possibly larger)) beyond bounds (12)'

Ответы на вопрос(1)

Ваш ответ на вопрос