2011-01-29 3 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; 

} 

,이 게터 기능이 발생합니다. EXC_BAD_ACCESS

sqllite 데이터베이스에는 두 개의 레코드가 있습니다.

왜 예외입니까? 내가 sectionNameKeyPath을 nil로 설정했기 때문입니까? 또는 뷰의 dataSource를이 컨트롤러에 설정하지 않았기 때문에? "난 numberOfRowsInSection의 %"대신

@property (nonatomic, readonly) NSUInteger numberOfObjects 

사용 @

+0

크래시 로그의 내용은 무엇입니까? – WrightsCS

답변

4

는 "numberOfRowsInSection의 %의 @"와 numberOfObjects @ 객체를 기록하고 있기 때문에이 int 형이다.

+0

대단히 감사합니다! 그것은 정확히 문제입니다! 며칠 동안 문서를 조사해 왔지만 NSLog/형식 문자열 문제 일 수 있다고는 생각하지 못했습니다. –

+0

다행입니다. – v01d

관련 문제