2011-10-21 9 views
0
CoreData: error: Serious application error. An exception was caught from the delegate of 

NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of sections. 
The number of sections contained in the table view after the update (1) must be equal to the number of sections contained in the table view before the update (0), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted). with userInfo (null) 

このようなエラーはありますか?どうやって知ることが出来ますか?私のコードで何が間違っているのですか?私はそのエラーを理解していません。誰が私にそれを教えてくれる?私はその地獄をどうやって修正することができますか?coredataエラーMake tableViewを表示できません(NSFetchResultsController)

セクションの番号は常に1です。なぜ更新前に0から始まるのですか?更新する前にセクションが1つしかないということをテーブルに記録するにはどうすればよいですか?

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     return [[self.FetchController sections] count]; 
    } 

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     id <NSFetchedResultsSectionInfo> sectionInfo = [[self.FetchController sections] objectAtIndex:section]; 
     /*int numberOfRow=[sectionInfo numberOfObjects]-(self.numberOf20SkipFromtheBeginning*20); 
     numberOfRow = MIN(20,numberOfRow);*/ 
     //int numberOfRow=MIN(100,[sectionInfo numberOfObjects]); 
     CalledRowCountingNotYetCallRowForSection=true; 
     [self.tableViewA setBounces:YES]; 

     if([sectionInfo numberOfObjects]>100){ 
      //[Timer searchCriteriaChanged]; 
      CLog(@"Something Wrong This NumberOfRow: %d", [sectionInfo numberOfObjects]); 
     } 


     return [sectionInfo numberOfObjects]; 
    } 

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     DLog(@"Function TableView AT listnewController"); 

     CalledRowCountingNotYetCallRowForSection =false; 
     if ([self tableView:tableView numberOfRowsInSection:indexPath.section]==0) 
     { 
      DLog(@"Something is VERY WRONG. Number of Section: %d" ,indexPath.section); 
     } 
     DLog(@"Indexpath at cellForRowAtIndexPath : %d", indexPath); 
     Business * theBiz=[self.FetchController objectAtIndexPath:indexPath]; 
     return theBiz.CustomCell; 

    } 

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     DLog(@"Function didselectrowatindexpath listnewcontroller"); 
     //[BNUtilitiesQuick UtilitiesQuick].currentBusiness=[[self.FetchController fetchedObjects] objectAtIndex:[indexPath row]+self.numberOf20SkipFromtheBeginning*20]; 
     [BNUtilitiesQuick UtilitiesQuick].currentBusiness=[[self.FetchController fetchedObjects] objectAtIndex:[indexPath row]]; 
     [BNUtilitiesQuick SafelyPushControllerAtNavigationController:[BNUtilitiesQuick NearbyIsiKota].mDetailBusiness atNavigationController:[BNUtilitiesQuick NearbyIsiKota].navigationController]; 
    } 

    - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { 
    DLog(@"controllerWillChangeContent: %@", controller); 
    [self.tableViewA beginUpdates]; 

} 


- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo 
      atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { 

    DLog(@"didChangeSection: %@", controller); 

    switch(type) { 
     case NSFetchedResultsChangeInsert: 
      [self.tableViewA insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; 
      break; 

     case NSFetchedResultsChangeDelete: 
      [self.tableViewA deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; 
      break; 
    } 
} 


- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject 
     atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type 
     newIndexPath:(NSIndexPath *)newIndexPath { 

    DLog(@"controller:%@\ndidChangeObject:%@\natIndexPath:%@\nforChangeType:%d\nnewIndexPath:%@\n",controller, anObject, indexPath, type, newIndexPath); 

    UITableView *tableView = self.tableViewA; 
    DLog(@"%@", self.tableViewA); 
    switch(type) { 
     case NSFetchedResultsChangeInsert: 
       [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationRight]; 
      break; 

     case NSFetchedResultsChangeDelete: 
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; 
      break; 

     case NSFetchedResultsChangeUpdate: 

      //[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; 
      //[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationRight]; 
      //[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; 
      break; 

     case NSFetchedResultsChangeMove: 
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; 
      [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationRight]; 
      break; 
    } 

} 


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { 
    [self.tableViewA endUpdates]; 
} 

答えて

2

これが最も可能性が高いことが1つを必要としないときNSFetchedResultsControllerためsectionNameKeyPathを提供することで引き起こされます。

sectionNameKeyPathを指定しても、そのキーパスに値が存在しない場合、フェッチされた結果コントローラはテーブルにゼロセクションがあると報告します。そのキーパスが値を取得した場合、フェッチされた結果コントローラは、テーブルに1つ以上のセクションがあることを報告します。

修正するには、フェッチ結果コントローラを初期化するときにsectionNameKeyPathが空であることを確認してください。 numberOfSectionsInTableView:を常に0または1を返すように配線することもできます。

関連する問題