2014-07-07 3 views
0

Parse.com에서 정보를 읽어야하는 Xcode 앱이 있습니다.Xcode에서 개체를 검색 할 수 없습니다.

- (void) initializeContent 
{ 
    [self queryParse: @"MyClassName"]; 
} 

- (void) queryParse:(NSString *) className 
{ 
    NSLog(@"Class Name Is: %@", className); 

    PFQuery *query = [PFQuery queryWithClassName:className]; 

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) 
    { 
     if (!error) 
     { 
      myObjectsArray = [[NSArray alloc] initWithArray:objects]; 
      NSLog(@"Objects Array: %@", myObjectsArray); 
     } 
     else 
     { 
      NSLog(@"Error retrieving objects: %@ %@", error, [error userInfo]); 
     } 

    }]; 
} 

이것은 구문 분석에서 개체를 반환 내있는 viewDidLoad에서

나는 호출

[self initializeContent]; 

를 호출합니다. 이 방법은 NULL을 반환하고 왜 두 번에 호출되는 이유

그러나, 다음은 구문 분석에서 아무것도 반환하지 않으며 방법은 스택 트레이스에서 볼 수 있듯이 두 번 호출됩니다

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 

    PFObject *tempObject = [myObjectsArray objectAtIndex:indexPath.row]; 
    NSLog(@"Temp Object: %@", tempObject); 

    cell.textLabel.text = [tempObject objectForKey:@"MyClassName"]; 

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    return cell; 
} 

는 아는 사람 있나요 cellForRowAtIndexPath 메소드?

enter image description here

답변

1

NSLog(@"Temp Object: %@", tempObject);는 tempObject에 description를 호출합니다. 이 메서드는 문자열 "(null)"을 반환하지만 객체 자체는 nil이 아닙니다. NSArray에는 nil 항목을 포함 할 수 없습니다. 그것은 Parse API가 요청을 리턴하고 있기 때문에 NSNull 값 객체 일 수 있습니다. (tableView:numberOfRowsInSection: 2를 반환) 데이터 소스가 두 개의 항목이 있다고하기 때문에 -

그것은 NSLog(@"Temp Object: %@", tempObject);cellForRowAtIndexPath: 내부에 두 번 호출되고 있다는 것은 아니지만, cellForRowAtIndexPath: 두 번 호출되는 가능성이 높습니다.

관련 문제