0

因此,我正在使用 RestKit 访问 Web 服务并从那里检索数据。到目前为止,我有两个视图,检索数据的那部分很好,我得到了我需要的 100 个对象,将它们保存到一个名为“songs”的数组中。

这是 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(...) 的第一行放置一个调试器,但程序没有进入那里。我觉得我忘记了一些非常简单的事情,但我似乎无法弄清楚是什么。

有人能帮助我吗?

4

1 回答 1

0

你永远不会启动一个新的单元格。您需要添加如下一行:

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

在您致电后

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TopListCellIdentifier];
于 2012-04-13T17:41:45.267 回答