2011-01-29 10 views
0

は、私がEXC_BAD_ACCESS:コアデータ、NSFetchedResultsControllerと私のUITableViewControllerクラスでnumberOfRowsInSection

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    id <NSFetchedResultsSectionInfo> sectionInfo = [[[self fetchedResultsController] sections] objectAtIndex:section]; 
    NSLog(@"numberOfRowsInSection %@", [sectionInfo numberOfObjects]); 
    return [sectionInfo numberOfObjects]; 

} 

それを、アプリがこの時点までに実行されますどういうわけかNSFetchResultsController

-(NSFetchedResultsController*) fetchedResultsController { 

    if (_fetchedResultsController == nil) { 
     FlipPadAppDelegate* app = (FlipPadAppDelegate*) [[UIApplication sharedApplication] delegate]; 
     NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init]; 
     [fetchRequest setEntity: 
      [NSEntityDescription entityForName:@"FundClass" inManagedObjectContext:[app managedObjectContext]]]; 
     NSSortDescriptor* sortdesp = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; 
     [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortdesp]]; 

     [fetchRequest setFetchBatchSize:20]; 

     _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest 
                     managedObjectContext:[app managedObjectContext] 
                     sectionNameKeyPath:nil 
                        cacheName:@"_Stock"]; 


     _fetchedResultsController.delegate = self; 
     [fetchRequest release]; 
     [sortdesp release]; 

     NSError *error; 
     if (![[self fetchedResultsController] performFetch:&error]) { 
      // Handle error 
      NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 

     } 
    } 

    return _fetchedResultsController; 

} 

、このゲッター機能を持っています火災a EXC_BAD_ACCESS

sqlliteデータベースには2つのレコードがあります。

なぜ例外ですか?それは私がsectionNameKeyPathをnilに設定したからですか?または、私はこのコントローラにビューのdataSourceを設定していないため? "私numberOfRowsInSection%" を代わりに

@property (nonatomic, readonly) NSUInteger numberOfObjects 

使用@:

+0

クラッシュログには何が表示されますか? – WrightsCS

答えて

4

あなたは "numberOfRowsInSectionの%の@" とnumberOfObjects @オブジェクトをログに記録されるためには、int型です。

+0

ありがとう!それはまさに問題です!私は数日間ドキュメンテーションを調べてきましたが、NSLog /フォーマット文字列の問題ではないとは思っていませんでした。 –

+0

うれしい私は助けることができました! – v01d

関連する問題