7

私はこれに完全に悩まされており、何が欠けているのかわかりません。おそらく、コアデータについて学ぶべきことはまだたくさんあります。

これは、セクションのないテーブルを表示するフェッチ済み結果コントローラーですが、検索表示コントローラーは機能します。

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

sectionNameKeyPathを適用するとすぐに、セクションを追加します。セクションが追加されますが、検索ディスプレイ コントローラーが壊れており、次のエラーがスローされます。

*** 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])'

そして、ここに私のテーブル ビュー データ ソースの実装があります。filteredListは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;
    }
}

次の行のcellForRowAtIndexPathで例外がスローされます:-

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

さらに情報を提供する必要があるかどうか尋ねてください..私はこれについて頭を悩ませています..

4

1 に答える 1

3

-dequeueReusableCellWithIdentifier:使用してみてください-dequeueReusableCellWithIdentifier:forIndexPath:.

于 2013-02-10T06:24:15.223 に答える