2012-04-13 3 views
0

그래서 RestKit을 사용하여 웹 서비스에 액세스하고 여기에서 데이터를 검색합니다. 지금까지 두 가지 뷰가 있었고 데이터를 검색하는 부분은 훌륭했습니다. 그리고 필요한 100 개의 객체를 가져 와서 "노래"라는 배열에 저장했습니다. I는 두 개의보기가,didLoadObjects의 배열에서 cellForRowAtIndexPath로 데이터를 전달할 수 있습니까?

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects { 
    NSLog(@" Reached didLoadObjects: %d", [objects count]); 

    self.songs = objects; 
    NSLog(@"%@",self.songs); 
} 

확인하고, 문제는 두 번째에 물론이다 : 여기

는 didLoadObjects이다. 나는 스토리 보드를 사용하고있다. tableView 셀에 "TopListCellIdentifier"라는 식별자를 부여했습니다.

그래서 객체가 100 개 모두 명령 줄에 "인쇄"되지만 cellForRowAtIndexPath 내부의 배열에서 데이터에 액세스하려고하면 문제가 발생합니다. 필요한 정보 (예 : 아들, 아티스트, 커버, 그런 것들)를 표시하는 사용자 정의 tableViewCell이 있어야합니다. 따라서 앱을 시작할 때 첫 번째보기는 괜찮지 만 두 번째보기에는 100 개의 셀이 있지만 정보는 없습니다. 다음은 cellForRowAtIndexPath 코드입니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *TopListCellIdentifier = @"TopListCellIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TopListCellIdentifier]; 

    // Loading the Cover Images in the Background 
    // Cover Image: Tag 1 
    [((HJManagedImageV*)[cell viewWithTag:1]) clear]; 
    HJManagedImageV* thumbImage = ((HJManagedImageV*)[cell viewWithTag:1]); 
    NSString *thumbUrl = [[self.songs objectAtIndex:[indexPath row]] thumbnail]; 

    thumbImage.url = [NSURL URLWithString:thumbUrl]; 
    [[ImageHandler sharedHandler].imgManager manage:thumbImage]; 

    //Song and Artist: Tag 2 and 3 
    ((UILabel*)[cell viewWithTag:2]).text = [[self.songs objectAtIndex:[indexPath row]] title]; 
    ((UILabel*)[cell viewWithTag:3]).text = [[self.songs objectAtIndex:[indexPath row]] artist]; 

    //Arrow Up/Down/Same: Tag 4 
    //TODO 

    //Position Number: Tag 5 
    ((UILabel*)[cell viewWithTag:5]).text = [NSString stringWithFormat:@"%d.", [indexPath row]+1]; 

    return cell; 
} 

나는 cellRow (...)의 첫 번째 줄에 디버거를 넣으려고했으나 프로그램이 거기에 입력하지 않았습니다. 나는 아주 단순한 것을 잊고있는 것처럼 느껴진다. 그러나 나는 무엇을 알아낼 수없는 것처럼 느껴진다.

누군가 나를 도와 줄 수 있습니까?

답변

0

당신은 새로운 세포를 초기화하지 않습니다. 당신은 iOS5를위한에 + (한 자신의 휴대 식별자가 존재하는) 그는 **입니다 ** 점점 필요하지 않습니다

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TopListCellIdentifier]; 
+0

에 전화 후

if (nil == cell) cell = [[UITalbeViewCell alloc] init... 

: 당신은 같은 라인을 추가 할 필요가 세포, 그들은 단지 비어 있습니다. – lnafziger

+0

몇 가지 코드를 자세하게 입력 해 주실 수 있습니까? 또는 몇 가지 예를 들어주세요. – JoaoTMDias

+0

그건 내가 생각한거야. 나는 iOS 5를 위해 그것을하지 않는다. 아직도 나는 지긋 지긋한 세포를 인쇄 할 수 없다. ... / – JoaoTMDias

관련 문제