2012-01-17 4 views
1

아래 코드를 참조하십시오. self.objects가 존재한다는 것을 증명하기 바로 직전에 [self.objects count]에 액세스하면이 오류가 발생하는 이유는 무엇입니까? .H 파일에ios 5 - EXC_BAD_ACCESS 오류

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    NSLog(@"HERE: %@", self.objects); //this logs the array - no error 
    NSLog(@"num rows: %@", [self.objects count]); //this line throws the error 
    return [self.objects count]; 
} 

나는이 있습니다

@synthesize objects = _objects; 

답변

2

당신은 제대로 로그 문자열을 포맷해야합니다 :

NSLog(@"num rows: %@", [self.objects count]); //this line throws the error 
@interface YouTubeViewController_iPad : UITableViewController 
{ 
    NSArray *_objects; 
} 

@property (nonatomic, retain) NSArray *objects; 

과하는 .m 파일에

[self.objects count]는 NSInteger를 반환합니다. 정수입니다. 정수가 객체가 아니라는 것을 이해하는 것이 중요합니다.

대신을 시도해보십시오

NSLog(@"num rows: %i", [self.objects count]); //Notice the string formatter 
2

오류에서 :

NSLog(@"num rows: %@", [self.objects count]); //this line throws the error 

업데이트와 :

NSLog(@"num rows: %d", [self.objects count]); //this line throws the error