2012-04-13 37 views
0

因此,我使用RestKit訪問Web服務並從那裏檢索數據。 到目前爲止,我有兩個視圖,檢索數據的部分很好,我得到了我需要的100個對象,將它們保存到一個名爲「歌曲」的數組中。如何將數據從didLoadObjects中的數據傳遞到cellForRowAtIndexPath

這裏是didLoadObjects:

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

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

好吧,我有兩個觀點,問題是,當然,在第二個。我正在使用故事板。我給了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

你永遠不會啓動一個新的單元格。您需要添加這樣一行:你的電話後

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

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

你並不需要爲iOS5的+(只要他的小區標識存在)和他** **是獲得細胞,他們只是空的。 – lnafziger 2012-04-13 17:49:51

+0

請問您能詳細說明一些代碼嗎?或者請舉個例子。 – JoaoTMDias 2012-04-13 18:01:04

+0

這就是我的想法。我不會爲iOS 5做到這一點。但我無法打印該死的細胞...:/ – JoaoTMDias 2012-04-13 18:02:48

相關問題