Sectioning Fetched Results Controller breaks Search Display

I'm absolutely bamboozled by this and can't work out what am I missing. Perhaps a lot still to learn about core data.

This is my Fetched Results Controller which displays a section-less table but my search display controller works:

self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
                                                                    managedObjectContext:self.buckyballDatabase.managedObjectContext
                                                                      sectionNameKeyPath:nil
                                                                               cacheName:nil];

WHEREAS as soon as I apply a sectionNameKeyPath, to add sections. Sections get added but my search display controller is broken, throwing the below error:

*** Assertion failure in -[UITableViewRowData rectForRow:inSection:], /SourceCache/UIKit_Sim/UIKit-2372/UITableViewRowData.m:1630
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path (<NSIndexPath 0x7481040> 2 indexes [0, 1])'

And here are my Table view data source implementations Where filteredList is an NSArray:-

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView == self.tableView)
    {
        return [[self.fetchedResultsController sections] count];
    }
    else
    {
        return 1;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    if (tableView == self.tableView)
    {
        return [[[self.fetchedResultsController sections] objectAtIndex:section] numberOfObjects];
    }
    else
    {
        return [self.filteredList count];
    }
}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (tableView == self.tableView)
    {
        return [[[self.fetchedResultsController sections] objectAtIndex:section] name];
    }
    else
    {
        return nil;
    }
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    if (tableView == self.tableView)
    {
        if (index > 0)
        {
            return [self.fetchedResultsController sectionForSectionIndexTitle:title atIndex:index-1];
        }
        else
        {
            self.tableView.contentOffset = CGPointZero;
            return NSNotFound;
        }
    }
    else
    {
        return 0;
    }
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    if (tableView == self.tableView)
    {
        NSMutableArray *index = [NSMutableArray arrayWithObject:UITableViewIndexSearch];
        NSArray *initials = [self.fetchedResultsController sectionIndexTitles];
        [index addObjectsFromArray:initials];
        return index;
    }
    else
    {
        return nil;
    }
}

Exception is thrown in cellForRowAtIndexPath at the below line:-

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier
                                                             forIndexPath:indexPath];

Please do ask if need to provide more information.. I'm scratching my head so much on this one..


尝试使用-dequeueReusableCellWithIdentifier:而不是-dequeueReusableCellWithIdentifier:forIndexPath:.

链接地址: http://www.djcxy.com/p/11468.html

上一篇: 在Clojure中保留带有索引的有状态查找表的习惯性方法

下一篇: 截取获取的结果控制器中断搜索显示